Add basic_json::get_to function.

Takes an lvalue reference, and returns the same reference.

This allows non-default constructible types to be converted without
specializing adl_serializer.
This overload does not require CopyConstructible either.

Implements #1227
This commit is contained in:
Théo DELRIEU 2018-09-10 12:56:24 +02:00
parent 680a4ab672
commit 521fe49fec
No known key found for this signature in database
GPG key ID: 7D6E00D1DF01DEAF
5 changed files with 174 additions and 7 deletions

View file

@ -298,6 +298,19 @@ TEST_CASE("basic usage", "[udt]")
CHECK(book == parsed_book);
}
SECTION("via explicit calls to get_to")
{
udt::person person;
udt::name name;
json person_json = big_json["contacts"][0]["person"];
CHECK(person_json.get_to(person) == sfinae_addict);
// correct reference gets returned
person_json["name"].get_to(name).m_val = "new name";
CHECK(name.m_val == "new name");
}
SECTION("implicit conversions")
{
const udt::contact_book parsed_book = big_json;