mirror of
https://github.com/nlohmann/json.git
synced 2025-07-28 12:02:00 +03:00
Merge pull request #1301 from theodelrieu/fix/1299
add new is_constructible_* traits used in from_json
This commit is contained in:
@ -121,6 +121,28 @@ struct nocopy
|
||||
j = {{"val", n.val}};
|
||||
}
|
||||
};
|
||||
|
||||
struct Data
|
||||
{
|
||||
std::string a;
|
||||
std::string b;
|
||||
};
|
||||
|
||||
void from_json(const json& j, Data& data)
|
||||
{
|
||||
j["a"].get_to(data.a);
|
||||
j["b"].get_to(data.b);
|
||||
}
|
||||
|
||||
bool operator==(Data const& lhs, Data const& rhs)
|
||||
{
|
||||
return lhs.a == rhs.a && lhs.b == rhs.b;
|
||||
}
|
||||
|
||||
bool operator!=(Data const& lhs, Data const& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
@ -1665,4 +1687,24 @@ TEST_CASE("regression tests")
|
||||
not std::is_constructible<json, std::variant<int, float>>::value, "");
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("issue #1299 - compile error in from_json converting to container "
|
||||
"with std::pair")
|
||||
{
|
||||
json j =
|
||||
{
|
||||
{"1", {{"a", "testa_1"}, {"b", "testb_1"}}},
|
||||
{"2", {{"a", "testa_2"}, {"b", "testb_2"}}},
|
||||
{"3", {{"a", "testa_3"}, {"b", "testb_3"}}},
|
||||
};
|
||||
|
||||
std::map<std::string, Data> expected
|
||||
{
|
||||
{"1", {"testa_1", "testb_1" }},
|
||||
{"2", {"testa_2", "testb_2"}},
|
||||
{"3", {"testa_3", "testb_3"}},
|
||||
};
|
||||
const auto data = j.get<decltype(expected)>();
|
||||
CHECK(expected == data);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user