Allow implicit conversion basic_json -> string_view
This commit is contained in:
parent
821517f95d
commit
f9bc348d1b
@ -2867,9 +2867,6 @@ 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_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
|
||||
, int >::type = 0 >
|
||||
|
||||
@ -15649,9 +15649,6 @@ 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_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
|
||||
, int >::type = 0 >
|
||||
|
||||
@ -51,20 +51,6 @@ using nlohmann::json;
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
template<typename From, typename To>
|
||||
struct is_implicitly_convertible
|
||||
{
|
||||
private:
|
||||
template <typename C>
|
||||
static std::true_type test(decltype(&C::operator To));
|
||||
|
||||
template <typename C>
|
||||
static std::false_type test(...);
|
||||
|
||||
public:
|
||||
static constexpr bool value = std::is_same<std::true_type, decltype(test<From>(nullptr))>::value;
|
||||
};
|
||||
|
||||
TEST_CASE("value conversion")
|
||||
{
|
||||
SECTION("get an object (explicit)")
|
||||
@ -494,7 +480,8 @@ TEST_CASE("value conversion")
|
||||
#if defined(JSON_HAS_STRING_VIEW)
|
||||
SECTION("std::string_view")
|
||||
{
|
||||
static_assert(!is_implicitly_convertible<decltype(j), std::string_view>::value);
|
||||
std::string_view s = j;
|
||||
CHECK(json(s) == j);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user