cppx-core
dynamic-size-checking.hpp
Go to the documentation of this file.
1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi").
2 
3 #include <cppx-core/language/syntax/macro-use.hpp> // CPPX_USE_STD
6 
7 #include <bitset> // std::bitset
8 #include <iterator> // std::(begin, end, size)
9 #include <string> // std::(basic_string, char_traits)
10 #include <string_view> // std::basic_string_view
11 
12 namespace cppx
13 {
14  CPPX_USE_STD( basic_string, basic_string_view, bitset, char_traits, size );
15 
16  template< class Collection >
17  constexpr auto n_items_of( const Collection& c ) noexcept
18  -> Size
19  { return size( c ); }
20 
21  template< size_t n >
22  auto n_items_of( const bitset<n>& bits ) noexcept
23  -> Size
24  { return bits.count(); }
25 
26  template< class Char >
27  inline auto length_of( const P_<const Char> s ) noexcept
28  -> Size
29  { return char_traits<Char>::length( s ); }
30 
31  template< class Char >
32  inline auto length_of( const basic_string<Char>& s ) noexcept
33  -> Size
34  { return s.length(); }
35 
36  template< class Char >
37  inline auto length_of( const basic_string_view<Char>& sv ) noexcept
38  -> Size
39  { return sv.length(); }
40 
41 } // namespace cppx
Some_type * P_
Creates a raw pointer type.
constexpr auto n_items_of(const Collection &c) noexcept -> Size
CPPX_USE_STD(basic_string, basic_string_view, bitset, char_traits, size)
Simple type builders Type_, P_, R_, Raw_array_ and Raw_array_of_.
Signed_< size_t > Size
A Signed_ equivalent of size_t.
Macros for generating more concise and clear using statements, primarily $use_cppx and $use_std,...
auto length_of(const P_< const Char > s) noexcept -> Size
Static size checkers: bits_per_, array_size_of (raw array, array and bitset) and length_of_literal (a...