From 33dfc474bd302e36de806060cd1f0dd85fed97a3 Mon Sep 17 00:00:00 2001 From: roker Date: Thu, 6 May 2021 11:22:18 +0200 Subject: [PATCH] =?UTF-8?q?add=20string=5Fview.hh=20=E2=80=93=20stolen=20f?= =?UTF-8?q?rom=20pEpMIME.=20:-D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/string_view.hh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/string_view.hh diff --git a/src/string_view.hh b/src/string_view.hh new file mode 100644 index 0000000..983fda8 --- /dev/null +++ b/src/string_view.hh @@ -0,0 +1,41 @@ +// 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 + +namespace pEp +{ + typedef std::string_view string_view; +} + +#else // in C++11 / C++14 use boost::string_view instead. +# include + +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 ::operator+=; +} // end of namespace pEp + +#endif // C++17 switch + +#endif // PEP_DATATYPES_CONFIG_HH