cppx-core
basic-string-building.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
4 #include <cppx-core/language/types/C_str_.hpp> // cppx::C_str
5 
6 #include <string> // std::string
7 #include <string_view> // std::string_view
8 #include <sstream> // std::ostringstream
9 
10 namespace cppx
11 {
12  CPPX_USE_STD( ostringstream, string, string_view );
13  using namespace std::string_literals; // E.g. ""s
14 
15  inline namespace basic_string_building
16  {
17  template< class Type >
18  inline auto operator<<( string& s, const Type& value )
19  -> string&
20  {
21  ostringstream stream;
22  stream << value;
23  s += stream.str();
24  return s;
25  }
26 
27  template<>
28  inline auto operator<< <char>( string& s, const char& more )
29  -> string&
30  {
31  s += more;
32  return s;
33  }
34 
35  template<>
36  inline auto operator<< <C_str>( string& s, const C_str& more )
37  -> string&
38  {
39  s += more;
40  return s;
41  }
42 
43  template<>
44  inline auto operator<< <string_view>( string& s, const string_view& more )
45  -> string&
46  {
47  s += more;
48  return s;
49  }
50 
51  template<>
52  inline auto operator<< <string>( string& s, const string& more )
53  -> string&
54  {
55  s += more;
56  return s;
57  }
58 
59  template< class Type >
60  inline auto operator<<( string&& s, Type const& value )
61  -> string&&
62  { return move( operator<<( s, value ) ); }
63 
64  } // namespace basic_string_building
65 } // namespace cppx
auto operator<<(string &&s, Type const &value) -> string &&
C_str for char const*; Wide_c_str for wchar_t const*; and Mutable_c_str and Mutable_wide_c_str as dit...
auto operator<<< char >(string &s, const char &more) -> string &
CPPX_USE_STD(basic_string, basic_string_view, bitset, char_traits, size)
auto operator<<< string >(string &s, const string &more) -> string &
auto operator<<< C_str >(string &s, const C_str &more) -> string &
C_str_< char > C_str
Definition: C_str_.hpp:38
Macros for generating more concise and clear using statements, primarily $use_cppx and $use_std,...
auto operator<<< string_view >(string &s, const string_view &more) -> string &