Added support for pre-c++17 experimental string_view (#607)

Added support for pre-c++17 experimental string_view
This commit is contained in:
Virgilio Alexandre Fornazin authored and Victor Zverovich committed 2017-12-16 09:03:11 -08:00
1 parent cabce31f45
commit 5705bf1c71
3 files changed
+63

No files matched your search

+36
View File
@@ -55,8 +55,15 @@
(defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910)
# include <string_view>
# define FMT_HAS_STRING_VIEW 1
# define FMT_HAS_EXPERIMENTAL_STRING_VIEW 0
#else
# define FMT_HAS_STRING_VIEW 0
# if (FMT_HAS_INCLUDE(<experimental/string_view>) && __cplusplus > 201402L)
# include <experimental/string_view>
# define FMT_HAS_EXPERIMENTAL_STRING_VIEW 1
# else
# define FMT_HAS_EXPERIMENTAL_STRING_VIEW 0
# endif
#endif
#if defined _SECURE_SCL && _SECURE_SCL
@@ -582,6 +589,26 @@ class BasicStringRef {
}
#endif
#if FMT_HAS_EXPERIMENTAL_STRING_VIEW
/**
\rst
Constructs a string reference from a ``std::experimental::basic_string_view`` object.
\endrst
*/
BasicStringRef(
const std::experimental::basic_string_view<Char, std::char_traits<Char>> &s)
: data_(s.data()), size_(s.size()) {}
/**
\rst
Converts a string reference to an ``std::string_view`` object.
\endrst
*/
explicit operator std::experimental::basic_string_view<Char>() const FMT_NOEXCEPT {
return std::experimental::basic_string_view<Char>(data_, size_);
}
#endif
/**
\rst
Converts a string reference to an ``std::string`` object.
@@ -1367,6 +1394,9 @@ class MakeValue : public Arg {
MakeValue(typename WCharHelper<const std::wstring &, Char>::Unsupported);
#if FMT_HAS_STRING_VIEW
MakeValue(typename WCharHelper<const std::wstring_view &, Char>::Unsupported);
#endif
#if FMT_HAS_EXPERIMENTAL_STRING_VIEW
MakeValue(typename WCharHelper<const std::experimental::wstring_view &, Char>::Unsupported);
#endif
MakeValue(typename WCharHelper<WStringRef, Char>::Unsupported);
@@ -1471,6 +1501,9 @@ class MakeValue : public Arg {
FMT_MAKE_STR_VALUE(const std::string &, STRING)
#if FMT_HAS_STRING_VIEW
FMT_MAKE_STR_VALUE(const std::string_view &, STRING)
#endif
#if FMT_HAS_EXPERIMENTAL_STRING_VIEW
FMT_MAKE_STR_VALUE(const std::experimental::string_view &, STRING)
#endif
FMT_MAKE_STR_VALUE(StringRef, STRING)
FMT_MAKE_VALUE_(CStringRef, string.value, CSTRING, value.c_str())
@@ -1486,6 +1519,9 @@ class MakeValue : public Arg {
FMT_MAKE_WSTR_VALUE(const std::wstring &, WSTRING)
#if FMT_HAS_STRING_VIEW
FMT_MAKE_WSTR_VALUE(const std::wstring_view &, WSTRING)
#endif
#if FMT_HAS_EXPERIMENTAL_STRING_VIEW
FMT_MAKE_WSTR_VALUE(const std::experimental::wstring_view &, WSTRING)
#endif
FMT_MAKE_WSTR_VALUE(WStringRef, WSTRING)