Introduce JSON_HAS_STRING_VIEW
This commit is contained in:
parent
ec06013eb0
commit
fdfdb70f75
@ -18,6 +18,13 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__has_include) && !defined(__INTELLISENSE__) && \
|
||||
!(defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1600)
|
||||
#define JSON_HAS_INCLUDE(x) __has_include(x)
|
||||
#else
|
||||
#define JSON_HAS_INCLUDE(x) 0
|
||||
#endif
|
||||
|
||||
// C++ language standard detection
|
||||
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
|
||||
#define JSON_HAS_CPP_17
|
||||
@ -26,6 +33,12 @@
|
||||
#define JSON_HAS_CPP_14
|
||||
#endif
|
||||
|
||||
#if (JSON_HAS_INCLUDE(<string_view>) && \
|
||||
(__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \
|
||||
(defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910)
|
||||
# define JSON_HAS_STRING_VIEW
|
||||
#endif
|
||||
|
||||
// disable float-equal warnings on GCC/clang
|
||||
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
|
||||
#pragma GCC diagnostic push
|
||||
|
||||
@ -17,7 +17,9 @@
|
||||
#undef JSON_UNLIKELY
|
||||
#undef JSON_DEPRECATED
|
||||
#undef JSON_NODISCARD
|
||||
#undef JSON_HAS_INCLUDE
|
||||
#undef JSON_HAS_CPP_14
|
||||
#undef JSON_HAS_CPP_17
|
||||
#undef JSON_HAS_STRING_VIEW
|
||||
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
||||
#undef NLOHMANN_BASIC_JSON_TPL
|
||||
|
||||
@ -72,7 +72,7 @@ SOFTWARE.
|
||||
#include <nlohmann/detail/value_t.hpp>
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
#if defined(JSON_HAS_CPP_17)
|
||||
#if defined(JSON_HAS_STRING_VIEW)
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
@ -2868,7 +2868,7 @@ class basic_json
|
||||
#ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015
|
||||
and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
|
||||
#endif
|
||||
#if defined(JSON_HAS_CPP_17)
|
||||
#if defined(JSON_HAS_STRING_VIEW)
|
||||
and not std::is_same<ValueType, typename std::string_view>::value
|
||||
#endif
|
||||
and detail::is_detected<detail::get_template_function, const basic_json_t&, ValueType>::value
|
||||
|
||||
@ -469,6 +469,13 @@ class other_error : public exception
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__has_include) && !defined(__INTELLISENSE__) && \
|
||||
!(defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1600)
|
||||
#define JSON_HAS_INCLUDE(x) __has_include(x)
|
||||
#else
|
||||
#define JSON_HAS_INCLUDE(x) 0
|
||||
#endif
|
||||
|
||||
// C++ language standard detection
|
||||
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
|
||||
#define JSON_HAS_CPP_17
|
||||
@ -477,6 +484,12 @@ class other_error : public exception
|
||||
#define JSON_HAS_CPP_14
|
||||
#endif
|
||||
|
||||
#if (JSON_HAS_INCLUDE(<string_view>) && \
|
||||
(__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \
|
||||
(defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910)
|
||||
# define JSON_HAS_STRING_VIEW
|
||||
#endif
|
||||
|
||||
// disable float-equal warnings on GCC/clang
|
||||
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
|
||||
#pragma GCC diagnostic push
|
||||
@ -12841,7 +12854,7 @@ class serializer
|
||||
// #include <nlohmann/json_fwd.hpp>
|
||||
|
||||
|
||||
#if defined(JSON_HAS_CPP_17)
|
||||
#if defined(JSON_HAS_STRING_VIEW)
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
@ -15637,7 +15650,7 @@ class basic_json
|
||||
#ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015
|
||||
and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
|
||||
#endif
|
||||
#if defined(JSON_HAS_CPP_17)
|
||||
#if defined(JSON_HAS_STRING_VIEW)
|
||||
and not std::is_same<ValueType, typename std::string_view>::value
|
||||
#endif
|
||||
and detail::is_detected<detail::get_template_function, const basic_json_t&, ValueType>::value
|
||||
@ -20841,8 +20854,10 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std
|
||||
#undef JSON_UNLIKELY
|
||||
#undef JSON_DEPRECATED
|
||||
#undef JSON_NODISCARD
|
||||
#undef JSON_HAS_INCLUDE
|
||||
#undef JSON_HAS_CPP_14
|
||||
#undef JSON_HAS_CPP_17
|
||||
#undef JSON_HAS_STRING_VIEW
|
||||
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
||||
#undef NLOHMANN_BASIC_JSON_TPL
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ using nlohmann::json;
|
||||
#define JSON_HAS_CPP_14
|
||||
#endif
|
||||
|
||||
#if defined(JSON_HAS_CPP_17)
|
||||
#if defined(JSON_HAS_STRING_VIEW)
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
@ -369,7 +369,7 @@ TEST_CASE("value conversion")
|
||||
std::string s = j.get<std::string>();
|
||||
CHECK(json(s) == j);
|
||||
}
|
||||
#if defined(JSON_HAS_CPP_17)
|
||||
#if defined(JSON_HAS_STRING_VIEW)
|
||||
SECTION("std::string_view")
|
||||
{
|
||||
std::string_view s = j.get<std::string_view>();
|
||||
@ -418,7 +418,7 @@ TEST_CASE("value conversion")
|
||||
"[json.exception.type_error.302] type must be string, but is number");
|
||||
}
|
||||
|
||||
#if defined(JSON_HAS_CPP_17)
|
||||
#if defined(JSON_HAS_STRING_VIEW)
|
||||
SECTION("exception in case of a non-string type using string_view")
|
||||
{
|
||||
CHECK_THROWS_AS(json(json::value_t::null).get<std::string_view>(), json::type_error&);
|
||||
@ -491,7 +491,7 @@ TEST_CASE("value conversion")
|
||||
CHECK(json(s) == j);
|
||||
}
|
||||
|
||||
#if defined(JSON_HAS_CPP_17)
|
||||
#if defined(JSON_HAS_STRING_VIEW)
|
||||
SECTION("std::string_view")
|
||||
{
|
||||
static_assert(!is_implicitly_convertible<decltype(j), std::string_view>::value);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user