* Add some restriction on pair partial specialization of to_json

Signed-off-by: Camille Bégué <camille.begue.pro@gmail.com>
This commit is contained in:
Camille Bégué 2019-10-21 17:50:15 +02:00 committed by Camille Bégué
parent 0245ae5157
commit 794a3d411a
3 changed files with 20 additions and 4 deletions

View file

@ -159,6 +159,16 @@ 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 #1805
/////////////////////////////////////////////////////////////////////
struct NotSerializableData
{
int mydata;
float myfloat;
};
TEST_CASE("regression tests")
{
@ -1820,6 +1830,12 @@ TEST_CASE("regression tests")
CHECK(j.contains(jptr1));
CHECK(j.contains(jptr2));
}
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, "");
static_assert(!std::is_constructible<json, std::pair<NotSerializableData, std::string>>::value, "");
static_assert(std::is_constructible<json, std::pair<int, std::string>>::value, "");
}
}
#if not defined(JSON_NOEXCEPTION)