Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix json: declare from_json_impl function definitions in advance when… #326

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion iguana/json_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end);
template <typename U, typename It, std::enable_if_t<smart_ptr_v<U>, int> = 0>
IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end);

template <typename U, typename It, std::enable_if_t<variant_v<U>, int> = 0>
IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end);

template <typename U, typename It,
std::enable_if_t<ylt_refletable_v<U>, int> = 0>
IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end) {
Expand Down Expand Up @@ -546,7 +549,7 @@ IGUANA_INLINE void from_json_variant(U &value, It &it, It &end,
end = temp_end;
}

template <typename U, typename It, std::enable_if_t<variant_v<U>, int> = 0>
template <typename U, typename It, std::enable_if_t<variant_v<U>, int>>
IGUANA_INLINE void from_json_impl(U &value, It &&it, It &&end) {
from_json_variant(value, it, end,
std::make_index_sequence<
Expand Down
15 changes: 13 additions & 2 deletions test/test_some.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, std::string> var;
std::vector<std::variant<int, my_variant_nest_t>> var1;
};
YLT_REFL(my_variant_t, name, var);
YLT_REFL(my_variant_t, name, var, var1);

TEST_CASE("test variant") {
std::variant<int, std::string> var;
std::variant<int, my_variant_nest_t> 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") {
Expand Down
Loading