cppx-core
String_value_view_.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 #include <cppx-core/collections/dynamic-size-checking.hpp> // cppx::length_of
7 #include <cppx-core/language/types/Truth.hpp> // cppx::Truth
8 
9 #include <string> // std::basic_string
10 #include <string_view> // std::basic_string_view
11 
12 namespace cppx
13 {
14  CPPX_USE_STD( basic_string, basic_string_view );
15 
16  template< class Char >
18  {
19  P_<const Char> m_p_start;
20  Size m_length;
21 
22  public:
23  auto is_empty() const
24  -> Truth
25  { return m_length == 0; }
26 
27  auto length() const
28  -> Size
29  { return m_length; }
30 
31  auto temporary_access() const
32  -> basic_string_view<Char>
33  { return basic_string_view<Char>( m_p_start, m_length ); }
34 
36  m_p_start( nullptr ),
37  m_length( 0 )
38  {}
39 
41  m_p_start( s ),
42  m_length( length_of( s ) )
43  {}
44 
45  String_value_view_( const basic_string<Char>& s ):
46  m_p_start( s.data() ),
47  m_length( s.length() )
48  {}
49  };
50 
51  template< class Char >
52  inline auto is_empty( const String_value_view_<Char>& svv )
53  -> Truth
54  { return svv.is_empty(); }
55 
58 
59 } // namespace cppx
Some_type * P_
Creates a raw pointer type.
auto length() const -> Size
A drop-in replacement for bool without implicit conversion from/to types other than bool.
Definition: Truth.hpp:34
String_value_view_(const basic_string< Char > &s)
auto temporary_access() const -> basic_string_view< Char >
Truth is a drop-in replacement for bool without implicit conversion from/to types other than bool.
CPPX_USE_STD(basic_string, basic_string_view, bitset, char_traits, size)
String_value_view_(const P_< const Char > s)
Simple type builders Type_, P_, R_, Raw_array_ and Raw_array_of_.
auto is_empty(const Collection &c) -> Truth
Definition: is_empty.hpp:33
auto is_empty() const -> Truth
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,...
Signed Size and Index, plus unsigned equivalents Unsigned_size and Unsigned_index.
auto length_of(const P_< const Char > s) noexcept -> Size