From 6b88a6149d0ee9865ed73e36206b720d4e4ee724 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 5 May 2018 22:12:07 +0100 Subject: Variant fix Swap the wrapper class from the variant to the containers because std::visit needs specialisations on the type which aren't present for the subclass. --- libjsonpp/jsonpp.h | 27 ++++++++++++++++++--------- libjsonpp/serialize.cpp | 2 +- libjsonpp/testSerialise.cpp | 14 +++++++------- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/libjsonpp/jsonpp.h b/libjsonpp/jsonpp.h index d56ca99..1a57389 100644 --- a/libjsonpp/jsonpp.h +++ b/libjsonpp/jsonpp.h @@ -18,18 +18,27 @@ namespace json { typedef double Number; typedef bool Boolean; class Null { }; - class Value; - typedef std::map Object; - typedef std::list Array; - typedef std::variant VT; - class Value : public VT { + class Object; + class Array; + typedef std::variant Value; + typedef std::map M; + class Object : public M { public: - Value() : VT(Null()) { } - - template - Value(const X & x) : VT(x) { } + using M::M; + }; + typedef std::list A; + class Array : public A { + public: + using A::A; }; + static_assert(std::is_move_constructible::value); + static_assert(std::is_nothrow_move_constructible::value); + static_assert(std::is_nothrow_move_constructible::value); + static_assert(std::is_move_assignable::value); + static_assert(std::is_nothrow_move_assignable::value); + static_assert(std::is_nothrow_move_assignable::value); + Value parseValue(std::istream &); Value parseValue(std::istream &, const std::string & encoding); Value parseValue(const Glib::ustring & s); diff --git a/libjsonpp/serialize.cpp b/libjsonpp/serialize.cpp index fe55fbd..055d36f 100644 --- a/libjsonpp/serialize.cpp +++ b/libjsonpp/serialize.cpp @@ -17,7 +17,7 @@ namespace json { << std::setfill('0') // for String \uNNNN ; } - void operator()(const VT & v) const { + void operator()(const Value & v) const { std::visit(*this, v); } void operator()(const std::string & str) const { diff --git a/libjsonpp/testSerialise.cpp b/libjsonpp/testSerialise.cpp index 66fc774..04f95ac 100644 --- a/libjsonpp/testSerialise.cpp +++ b/libjsonpp/testSerialise.cpp @@ -98,23 +98,23 @@ BOOST_AUTO_TEST_CASE( serialise_quotes ) BOOST_AUTO_TEST_CASE( serialise_complexObject ) { BOOST_REQUIRE_EQUAL("{\"a\":\"string\",\"b\":null,\"c\":64,\"d\":true,\"e\":{\"suba\":\"suba-val\",\"subb\":\"subb-val\"},\"f\":[true,false,-4.9,\"item\"]}", writeString( - json::Object({ + json::Object { {"a", "string"s}, - {"b", json::Null()}, + {"b", json::Null() }, {"c", 64.0}, {"d", true}, - {"e", json::Object({ + {"e", json::Object { {"suba", "suba-val"s}, {"subb", "subb-val"s} - }) + } }, - {"f", json::Array({ + {"f", json::Array { true, false, -4.9, "item"s - }), + }, } - }))); + })); } -- cgit v1.2.3