commit
7bcaba0ca9
4 changed files with 93 additions and 53 deletions
|
@ -97,7 +97,7 @@
|
|||
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
|
||||
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
|
||||
auto it = std::find_if(std::begin(m), std::end(m), \
|
||||
[j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
|
||||
[&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
|
||||
{ \
|
||||
return ej_pair.second == j; \
|
||||
}); \
|
||||
|
|
|
@ -2633,11 +2633,11 @@ class basic_json
|
|||
detail::has_non_default_from_json<basic_json_t, ValueType>::value,
|
||||
int> = 0>
|
||||
ValueType get() const noexcept(noexcept(
|
||||
JSONSerializer<ValueTypeCV>::from_json(std::declval<const basic_json_t&>())))
|
||||
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
|
||||
{
|
||||
static_assert(not std::is_reference<ValueTypeCV>::value,
|
||||
"get() cannot be used with reference types, you might want to use get_ref()");
|
||||
return JSONSerializer<ValueTypeCV>::from_json(*this);
|
||||
return JSONSerializer<ValueType>::from_json(*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -8062,7 +8062,7 @@ struct hash<nlohmann::json>
|
|||
/// @note: do not remove the space after '<',
|
||||
/// see https://github.com/nlohmann/json/pull/679
|
||||
template<>
|
||||
struct less< ::nlohmann::detail::value_t>
|
||||
struct less<::nlohmann::detail::value_t>
|
||||
{
|
||||
/*!
|
||||
@brief compare two value_t enum values
|
||||
|
|
|
@ -1801,7 +1801,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
|
||||
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
|
||||
auto it = std::find_if(std::begin(m), std::end(m), \
|
||||
[j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
|
||||
[&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
|
||||
{ \
|
||||
return ej_pair.second == j; \
|
||||
}); \
|
||||
|
@ -17176,11 +17176,11 @@ class basic_json
|
|||
detail::has_non_default_from_json<basic_json_t, ValueType>::value,
|
||||
int> = 0>
|
||||
ValueType get() const noexcept(noexcept(
|
||||
JSONSerializer<ValueTypeCV>::from_json(std::declval<const basic_json_t&>())))
|
||||
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
|
||||
{
|
||||
static_assert(not std::is_reference<ValueTypeCV>::value,
|
||||
"get() cannot be used with reference types, you might want to use get_ref()");
|
||||
return JSONSerializer<ValueTypeCV>::from_json(*this);
|
||||
return JSONSerializer<ValueType>::from_json(*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -159,6 +159,39 @@ bool operator==(Data const& lhs, Data const& rhs)
|
|||
|
||||
using float_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, float>;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// for #1647
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
namespace
|
||||
{
|
||||
struct NonDefaultFromJsonStruct { };
|
||||
|
||||
inline bool operator== (NonDefaultFromJsonStruct const& lhs, NonDefaultFromJsonStruct const& rhs)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
enum class for_1647 { one, two };
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(for_1647,
|
||||
{
|
||||
{for_1647::one, "one"},
|
||||
{for_1647::two, "two"},
|
||||
})
|
||||
}
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
template <>
|
||||
struct adl_serializer<NonDefaultFromJsonStruct>
|
||||
{
|
||||
static NonDefaultFromJsonStruct from_json (json const& j)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// for #1805
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
@ -1836,6 +1869,13 @@ TEST_CASE("regression tests")
|
|||
CHECK(j.contains(jptr1));
|
||||
CHECK(j.contains(jptr2));
|
||||
}
|
||||
|
||||
SECTION("issue #1647 - compile error when deserializing enum if both non-default from_json and non-member operator== exists for other type")
|
||||
{
|
||||
auto val = nlohmann::json("one").get<for_1647>();
|
||||
CHECK(val == for_1647::one);
|
||||
}
|
||||
|
||||
SECTION("issue #1805 - A pair<T1, T2> is json constructible only if T1 and T2 are json constructible")
|
||||
{
|
||||
static_assert(!std::is_constructible<json, std::pair<std::string, NotSerializableData>>::value, "");
|
||||
|
|
Loading…
Reference in a new issue