A C++ wrapper for the basic C datatypes defined by the pEpEngine.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.1 KiB

  1. // This file is under GNU General Public License 3.0
  2. // see LICENSE.txt
  3. #ifndef PEP_DATATYPES_STRING_VIEW_HH
  4. #define PEP_DATATYPES_STRING_VIEW_HH
  5. #if (__cplusplus >= 201606) // std::string_view is C++17.
  6. # include <string_view>
  7. namespace pEp
  8. {
  9. typedef std::string_view string_view;
  10. }
  11. #else // in C++11 / C++14 use boost::string_view instead.
  12. # include <boost/utility/string_view.hpp>
  13. namespace pEp
  14. {
  15. typedef boost::string_view string_view;
  16. // boost::string_view does not provide these operations, neither by boost nor by the stdlib. :-(
  17. inline
  18. std::string& operator+=(std::string& s, const string_view v)
  19. {
  20. s.append(v.data(), v.size());
  21. return s;
  22. }
  23. inline
  24. std::string operator+(std::string s, const string_view v)
  25. {
  26. return s += v;
  27. }
  28. // using ::std::operator+=;
  29. // using ::boost::operator+=;
  30. } // end of namespace pEp
  31. #endif // C++17 switch
  32. namespace pEp
  33. {
  34. constexpr
  35. string_view operator""_sv(const char* s, size_t sz) noexcept
  36. {
  37. return string_view(s,sz);
  38. }
  39. }
  40. #endif // PEP_DATATYPES_STRING_VIEW_HH