// Copyright 2020 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt #include #include #include #include #include #include #include namespace app { #if BOOST_VERSION < 108100 template, class D2 = boost::describe::describe_members, class En = std::enable_if_t::value && !std::is_union::value> > void tag_invoke( boost::json::value_from_tag const&, boost::json::value& v, T const & t ) { auto& obj = v.emplace_object(); boost::mp11::mp_for_each([&](auto D){ obj[ D.name ] = boost::json::value_from( t.*D.pointer ); }); } #endif struct A { int x; int y; }; BOOST_DESCRIBE_STRUCT(A, (), (x, y)) struct B { std::vector v; std::map m; }; BOOST_DESCRIBE_STRUCT(B, (), (v, m)) } // namespace app #include int main() { app::B b{ { { 1, 2 }, { 3, 4 } }, { { "k1", { 5, 6 } }, { "k2", { 7, 8 } } } }; std::cout << boost::json::value_from( b ) << std::endl; }