|
|
- // This file is under GNU General Public License 3.0
- // see LICENSE.txt
-
- #ifndef PEP_DATATYPES_STRING_VIEW_HH
- #define PEP_DATATYPES_STRING_VIEW_HH
-
- #if (__cplusplus >= 201606) // std::string_view is C++17.
- # include <string_view>
-
- namespace pEp
- {
- typedef std::string_view string_view;
- }
-
- #else // in C++11 / C++14 use boost::string_view instead.
- # include <boost/utility/string_view.hpp>
-
- namespace pEp
- {
- typedef boost::string_view string_view;
-
- // boost::string_view does not provide these operations, neither by boost nor by the stdlib. :-(
- inline
- std::string& operator+=(std::string& s, const string_view v)
- {
- s.append(v.data(), v.size());
- return s;
- }
-
- inline
- std::string operator+(std::string s, const string_view v)
- {
- return s += v;
- }
-
-
- // using ::std::operator+=;
- // using ::boost::operator+=;
- } // end of namespace pEp
-
- #endif // C++17 switch
-
-
- namespace pEp
- {
- constexpr
- string_view operator""_sv(const char* s, size_t sz) noexcept
- {
- return string_view(s,sz);
- }
- }
-
- #endif // PEP_DATATYPES_STRING_VIEW_HH
|