From bb1b4c934e728e9bedaa6d3a97f90807a2857fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= Date: Tue, 22 Aug 2017 23:40:10 +0200 Subject: [PATCH] fix from_json implementation for pair/tuple Introduced by 6e4910d5c5638bedbc3ff650d1b6b91249a927a3 Fixes #707 --- src/json.hpp | 8 ++++---- test/src/unit-constructor1.cpp | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 83c9ef2e5..ef55a93ce 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -1235,16 +1235,16 @@ void from_json(const BasicJsonType& j, ArithmeticType& val) } } -template -void from_json(const BasicJsonType& j, std::pair& p) +template +void from_json(const BasicJsonType& j, std::pair& p) { - p = {j.at(0), j.at(1)}; + p = {j.at(0).template get(), j.at(1).template get()}; } template void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence) { - t = std::make_tuple(j.at(Idx)...); + t = std::make_tuple(j.at(Idx).template get::type>()...); } template diff --git a/test/src/unit-constructor1.cpp b/test/src/unit-constructor1.cpp index da10ed2e1..10b5216dd 100644 --- a/test/src/unit-constructor1.cpp +++ b/test/src/unit-constructor1.cpp @@ -246,6 +246,7 @@ TEST_CASE("constructors") json j(p); CHECK(j.type() == json::value_t::array); + CHECK(j.get() == p); REQUIRE(j.size() == 2); CHECK(j[0] == std::get<0>(p)); CHECK(j[1] == std::get<1>(p)); @@ -262,11 +263,12 @@ TEST_CASE("constructors") SECTION("std::tuple") { - const auto t = std::make_tuple(1.0, "string", 42, std::vector {0, 1}); + const auto t = std::make_tuple(1.0, std::string{"string"}, 42, std::vector {0, 1}); json j(t); CHECK(j.type() == json::value_t::array); REQUIRE(j.size() == 4); + CHECK(j.get() == t); CHECK(j[0] == std::get<0>(t)); CHECK(j[1] == std::get<1>(t)); CHECK(j[2] == std::get<2>(t));