Browse Source

add u16string_view.

master
roker 4 years ago
parent
commit
b9a0dde181
  1. 18
      src/string_view.hh

18
src/string_view.hh

@ -9,7 +9,11 @@
namespace pEp namespace pEp
{ {
typedef std::string_view string_view; template<class CharT>
using basic_string_view = std::basic_string_view<CharT>;
typedef std::string_view string_view;
typedef std::u16string_view u16string_view;
} }
#else // in C++11 / C++14 use boost::string_view instead. #else // in C++11 / C++14 use boost::string_view instead.
@ -17,18 +21,24 @@ namespace pEp
namespace pEp namespace pEp
{ {
typedef boost::string_view string_view; template<class CharT>
using basic_string_view = boost::basic_string_view<CharT>;
typedef boost::string_view string_view;
typedef boost::u16string_view u16string_view;
// boost::string_view does not provide these operations, neither by boost nor by the stdlib. :-( // boost::string_view does not provide these operations, neither by boost nor by the stdlib. :-(
template<class CharT>
inline inline
std::string& operator+=(std::string& s, const string_view v) std::basic_string<CharT>& operator+=(std::basic_string<CharT>& s, const basic_string_view<CharT> v)
{ {
s.append(v.data(), v.size()); s.append(v.data(), v.size());
return s; return s;
} }
template<class CharT>
inline inline
std::string operator+(std::string s, const string_view v) std::basic_string<CharT> operator+(std::basic_string<CharT> s, const basic_string_view<CharT> v)
{ {
return s += v; return s += v;
} }

Loading…
Cancel
Save