|
7 | 7 | #include <type_traits>
|
8 | 8 | #include <utility>
|
9 | 9 |
|
| 10 | +// CXX_HAVE_STD_STRING_VIEW |
| 11 | +// |
| 12 | +// Checks whether C++17 std::string_view is available. |
| 13 | +#ifdef CXX_HAVE_STD_STRING_VIEW |
| 14 | +#error "CXX_HAVE_STD_STRING_VIEW cannot be directly set." |
| 15 | +#endif |
| 16 | + |
| 17 | +#ifdef __has_include |
| 18 | +#if __has_include(<string_view>) && __cplusplus >= 201703L |
| 19 | +#define CXX_HAVE_STD_STRING_VIEW 1 |
| 20 | +#endif |
| 21 | +#endif |
| 22 | + |
| 23 | +// For MSVC, `__has_include` is supported in VS 2017 15.3, which is later than |
| 24 | +// the support for <optional>, <any>, <string_view>, <variant>. So we use |
| 25 | +// _MSC_VER to check whether we have VS 2017 RTM (when <optional>, <any>, |
| 26 | +// <string_view>, <variant> is implemented) or higher. Also, `__cplusplus` is |
| 27 | +// not correctly set by MSVC, so we use `_MSVC_LANG` to check the language |
| 28 | +// version. |
| 29 | +#if defined(_MSC_VER) && _MSC_VER >= 1910 && \ |
| 30 | + ((defined(_MSVC_LANG) && _MSVC_LANG > 201402) || __cplusplus > 201402) |
| 31 | +#define CXX_HAVE_STD_STRING_VIEW 1 |
| 32 | +#endif |
| 33 | + |
| 34 | +#ifdef CXX_HAVE_STD_STRING_VIEW |
| 35 | +#include <string_view> |
| 36 | +#endif |
| 37 | + |
10 | 38 | namespace rust {
|
11 | 39 | inline namespace cxxbridge02 {
|
12 | 40 |
|
@@ -50,8 +78,13 @@ class Str final {
|
50 | 78 | Str() noexcept;
|
51 | 79 | Str(const Str &) noexcept;
|
52 | 80 |
|
| 81 | +#ifdef CXX_HAVE_STD_STRING_VIEW |
| 82 | + Str(std::string_view); |
| 83 | +#else |
53 | 84 | Str(const std::string &);
|
54 | 85 | Str(const char *);
|
| 86 | +#endif |
| 87 | + |
55 | 88 | Str(std::string &&) = delete;
|
56 | 89 |
|
57 | 90 | Str &operator=(Str) noexcept;
|
|
0 commit comments