From 0a084ca933466808b17d88828126a5cf431acd94 Mon Sep 17 00:00:00 2001 From: fesil <285451120@qq.com> Date: Tue, 19 Nov 2024 11:30:40 +0800 Subject: [PATCH] fix json: declare from_json_impl function definitions in advance when variant --- iguana/json_reader.hpp | 5 ++++- test/test_some.cpp | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/iguana/json_reader.hpp b/iguana/json_reader.hpp index 765815fe..1485f2bb 100644 --- a/iguana/json_reader.hpp +++ b/iguana/json_reader.hpp @@ -25,6 +25,9 @@ IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end); template , int> = 0> IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end); +template , int> = 0> +IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end); + template , int> = 0> IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end) { @@ -546,7 +549,7 @@ IGUANA_INLINE void from_json_variant(U &value, It &it, It &end, end = temp_end; } -template , int> = 0> +template , int>> IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end) { from_json_variant(value, it, end, std::make_index_sequence< diff --git a/test/test_some.cpp b/test/test_some.cpp index 97c4f0a8..4286eb4c 100644 --- a/test/test_some.cpp +++ b/test/test_some.cpp @@ -217,22 +217,33 @@ TEST_CASE("test throw while parsing an illegal number") { } } +struct my_variant_nest_t { + std::string a; + bool operator==(const my_variant_nest_t &o) const { return o.a == a; } +}; +YLT_REFL(my_variant_nest_t, a); + struct my_variant_t { std::string name; std::variant var; + std::vector> var1; }; -YLT_REFL(my_variant_t, name, var); +YLT_REFL(my_variant_t, name, var, var1); TEST_CASE("test variant") { std::variant var; + std::variant var1; var = 1; - my_variant_t v{"Hi", var}, v2; + var1 = my_variant_nest_t{"1234"}; + my_variant_t v{"Hi", var, {var1}}, v2; std::string s; iguana::to_json(v, s); std::cout << s << std::endl; iguana::from_json(v2, s); CHECK(v.var == v2.var); + CHECK(v.var1.size() == v2.var1.size()); + CHECK(v.var1[0] == v2.var1[0]); } TEST_CASE("test from issues") {