From c75fbe3255bdd3dffd4483ec6a5f48adc5453e28 Mon Sep 17 00:00:00 2001 From: Emil Dotchevski Date: Fri, 23 Jan 2026 19:50:15 -0500 Subject: [PATCH] Renamed various things --- doc/leaf.adoc | 132 +++++++++--------- include/boost/leaf/detail/all.hpp | 4 +- .../leaf/serialization/boost_json_encoder.hpp | 53 +++++++ .../leaf/serialization/json_encoder_boost.hpp | 49 ------- ...nlohmann.hpp => nlohmann_json_encoder.hpp} | 12 +- meson.build | 6 +- test/Jamfile.v2 | 16 +-- ...fail-serialization_boost_json_encoder.cpp} | 4 +- ...l-serialization_nlohmann_json_encoder.cpp} | 4 +- ...serialization_boost_json_encoder_test.cpp} | 4 +- ...ialization_nlohmann_json_encoder_test.cpp} | 4 +- ...t_test.cpp => boost_json_encoder_test.cpp} | 22 +-- ...est.cpp => nlohmann_json_encoder_test.cpp} | 8 +- 13 files changed, 153 insertions(+), 165 deletions(-) create mode 100644 include/boost/leaf/serialization/boost_json_encoder.hpp delete mode 100644 include/boost/leaf/serialization/json_encoder_boost.hpp rename include/boost/leaf/serialization/{json_encoder_nlohmann.hpp => nlohmann_json_encoder.hpp} (64%) rename test/{_compile-fail-serialization_json_encoder_boost.cpp => _compile-fail-serialization_boost_json_encoder.cpp} (77%) rename test/{_compile-fail-serialization_json_encoder_nlohmann.cpp => _compile-fail-serialization_nlohmann_json_encoder.cpp} (75%) rename test/{_hpp_serialization_json_encoder_boost_test.cpp => _hpp_serialization_boost_json_encoder_test.cpp} (67%) rename test/{_hpp_serialization_json_encoder_nlohmann_test.cpp => _hpp_serialization_nlohmann_json_encoder_test.cpp} (66%) rename test/{json_encoder_boost_test.cpp => boost_json_encoder_test.cpp} (94%) rename test/{json_encoder_nlohmann_test.cpp => nlohmann_json_encoder_test.cpp} (97%) diff --git a/doc/leaf.adoc b/doc/leaf.adoc index 6380abb..928c997 100644 --- a/doc/leaf.adoc +++ b/doc/leaf.adoc @@ -1811,7 +1811,7 @@ To support multiple output formats, pass multiple functions to `h.dispatch`: [source,c++] ---- h.dispatch( - [&](json_encoder_nlohmann & e) { output_at(e, x, name); }, + [&](nlohmann_json_encoder & e) { output_at(e, x, name); }, [&](xml_encoder & xe) { output_at(xe, x, name); } ); ---- @@ -1820,19 +1820,19 @@ h.dispatch( LEAF provides encoders for JSON serialization with two popular JSON libraries: -* <> for https://github.com/nlohmann/json[nlohmann/json] -* <> for https://www.boost.org/doc/libs/release/libs/json/[Boost.JSON] +* <> for https://github.com/nlohmann/json[nlohmann/json] +* <> for https://www.boost.org/doc/libs/release/libs/json/[Boost.JSON] -Below is an example using `json_encoder_nlohmann`. We just need to define the required `serialize` function template (see <>): +Below is an example using `nlohmann_json_encoder`. We just need to define the required `serialize` function template (see <>): [source,c++] ---- -#include +#include #include "nlohmann/json.hpp" namespace leaf = boost::leaf; -using json_encoder_nlohmann = leaf::serialization::json_encoder_nlohmann; +using nlohmann_json_encoder = leaf::serialization::nlohmann_json_encoder; namespace boost { namespace leaf { @@ -1841,7 +1841,7 @@ namespace serialization { template void serialize(Handle & h, T const & x, char const * name) { - h.dispatch([&](json_encoder_nlohmann & e) { + h.dispatch([&](nlohmann_json_encoder & e) { output_at(e, x, name); }); } @@ -1884,7 +1884,7 @@ leaf::try_handle_all( [](leaf::diagnostic_details const & dd) { nlohmann::json j; - json_encoder_nlohmann e(j); + nlohmann_json_encoder e(j); dd.serialize_to(e); std::cout << j.dump(2) << std::endl; } @@ -1906,7 +1906,7 @@ leaf::try_handle_all( [.text-right] <> | <> | <> -NOTE: In the example above, `e_api_response` uses an unqualified call to `to_json` for serialization. This is to demonstrate that `json_encoder_nlohmann` handles third party type with suitable `to_json` overloads automatically. If instead we defined a function `output` compatible with the LEAF serialization API, it would make `e_api_response` compatible with any LEAF encoder. +NOTE: In the example above, `e_api_response` uses an unqualified call to `to_json` for serialization. This is to demonstrate that `nlohmann_json_encoder` handles third party type with suitable `to_json` overloads automatically. If instead we defined a function `output` compatible with the LEAF serialization API, it would make `e_api_response` compatible with any LEAF encoder. ''' @@ -2862,28 +2862,28 @@ Reference: <> === Serialization -[[json_encoder_boost.hpp]] -==== `json_encoder_boost.hpp` +[[boost_json_encoder.hpp]] +==== `boost_json_encoder.hpp` ==== -.#include +.#include [source,c++] ---- namespace boost { namespace leaf { namespace serialization { - struct json_encoder_boost + struct boost_json_encoder { boost::json::value & v_; // Enabled if x is assignable to boost::json::value, or // if tag_invoke is defined for boost::json::value_from_tag. template - friend void output( json_encoder_boost &, T const & x ); + friend void output( boost_json_encoder &, T const & x ); template - friend void output_at( json_encoder_boost &, T const &, char const * name ); + friend void output_at( boost_json_encoder &, T const &, char const * name ); }; } @@ -2891,14 +2891,14 @@ namespace serialization ---- [.text-right] -Reference: <> +Reference: <> ==== -[[json_encoder_nlohmann.hpp]] -==== `json_encoder_nlohmann.hpp` +[[nlohmann_json_encoder.hpp]] +==== `nlohmann_json_encoder.hpp` ==== -.#include +.#include [source,c++] ---- namespace boost { namespace leaf { @@ -2906,16 +2906,16 @@ namespace boost { namespace leaf { namespace serialization { template - struct json_encoder_nlohmann + struct nlohmann_json_encoder { Json & j_; // Enabled if to_json is available for Json and T. template - friend void output( json_encoder_nlohmann &, T const & x ); + friend void output( nlohmann_json_encoder &, T const & x ); template - friend void output_at( json_encoder_nlohmann &, T const &, char const * name ); + friend void output_at( nlohmann_json_encoder &, T const &, char const * name ); }; } @@ -2923,7 +2923,7 @@ namespace serialization ---- [.text-right] -Reference: <> +Reference: <> ==== [[functions]] @@ -3657,6 +3657,42 @@ TIP: The contents of each Reference section are organized alphabetically. ''' +[[boost_json_encoder]] +=== `boost_json_encoder` + +.#include +[source,c++] +---- +namespace boost { namespace leaf { + +namespace serialization +{ + struct boost_json_encoder + { + boost::json::value & v_; + + // Enabled if x is assignable to boost::json::value, or + // if tag_invoke is defined for boost::json::value_from_tag. + template + friend void output( boost_json_encoder &, T const & x ); + + template + friend void output_at( boost_json_encoder &, T const &, char const * name ); + }; +} + +} } +---- + +The `boost_json_encoder` type serializes error objects to JSON format using https://www.boost.org/doc/libs/release/libs/json/[Boost.JSON]. The `output` function is enabled for: + +* Types directly assignable to `boost::json::value` +* Types for which a `tag_invoke` overload for `value_from_tag` can be found via ADL + +See <>. + +''' + [[context]] === `context` @@ -4442,46 +4478,10 @@ The `serialize_to` member function is used with the serialization system; see << ''' -[[json_encoder_boost]] -=== `json_encoder_boost` +[[nlohmann_json_encoder]] +=== `nlohmann_json_encoder` -.#include -[source,c++] ----- -namespace boost { namespace leaf { - -namespace serialization -{ - struct json_encoder_boost - { - boost::json::value & v_; - - // Enabled if x is assignable to boost::json::value, or - // if tag_invoke is defined for boost::json::value_from_tag. - template - friend void output( json_encoder_boost &, T const & x ); - - template - friend void output_at( json_encoder_boost &, T const &, char const * name ); - }; -} - -} } ----- - -The `json_encoder_boost` type serializes error objects to JSON format using https://www.boost.org/doc/libs/release/libs/json/[Boost.JSON]. The `output` function is enabled for: - -* Types directly assignable to `boost::json::value` -* Types for which a `tag_invoke` overload for `value_from_tag` can be found via ADL - -See <>. - -''' - -[[json_encoder_nlohmann]] -=== `json_encoder_nlohmann` - -.#include +.#include [source,c++] ---- namespace boost { namespace leaf { @@ -4489,23 +4489,23 @@ namespace boost { namespace leaf { namespace serialization { template - struct json_encoder_nlohmann + struct nlohmann_json_encoder { Json & j_; // Enabled if to_json is available for Json and T. template - friend void output( json_encoder_nlohmann &, T const & x ); + friend void output( nlohmann_json_encoder &, T const & x ); template - friend void output_at( json_encoder_nlohmann &, T const &, char const * name ); + friend void output_at( nlohmann_json_encoder &, T const &, char const * name ); }; } } } ---- -The `json_encoder_nlohmann` type serializes error objects to JSON format using unqualified calls to `to_json`. This is compatible with https://github.com/nlohmann/json[nlohmann/json]; See <>. +The `nlohmann_json_encoder` type serializes error objects to JSON format using unqualified calls to `to_json`. This is compatible with https://github.com/nlohmann/json[nlohmann/json]; See <>. ''' diff --git a/include/boost/leaf/detail/all.hpp b/include/boost/leaf/detail/all.hpp index ec58341..b5dfb54 100644 --- a/include/boost/leaf/detail/all.hpp +++ b/include/boost/leaf/detail/all.hpp @@ -11,6 +11,6 @@ #include #include #include -#include -#include +#include +#include #include diff --git a/include/boost/leaf/serialization/boost_json_encoder.hpp b/include/boost/leaf/serialization/boost_json_encoder.hpp new file mode 100644 index 0000000..4eac1b8 --- /dev/null +++ b/include/boost/leaf/serialization/boost_json_encoder.hpp @@ -0,0 +1,53 @@ +#ifndef BOOST_LEAF_SERIALIZATION_BOOST_JSON_ENCODER_HPP_INCLUDED +#define BOOST_LEAF_SERIALIZATION_BOOST_JSON_ENCODER_HPP_INCLUDED + +// Copyright 2018-2026 Emil Dotchevski and Reverge Studios, Inc. +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include + +namespace boost { namespace json { + +class value; +struct value_from_tag; + +} } + +namespace boost { namespace leaf { + +namespace serialization +{ + template + struct boost_json_encoder_ + { + Value & v_; + + template + friend auto output(boost_json_encoder_ & e, T const & x) -> decltype(std::declval() = x, void()) + { + e.v_ = x; + } + + template + friend auto output(boost_json_encoder_ & e, T const & x) -> decltype(tag_invoke(std::declval(), std::declval(), x), void()) + { + tag_invoke(ValueFromTag{}, e.v_, x); + } + + template + friend void output_at(boost_json_encoder_ & e, T const & x, char const * name) + { + if( e.v_.is_null() ) + e.v_.emplace_object(); + boost_json_encoder_ nested{e.v_.as_object()[name]}; + output(nested, x); + } + }; + + using boost_json_encoder = boost_json_encoder_<>; +} + +} } + +#endif diff --git a/include/boost/leaf/serialization/json_encoder_boost.hpp b/include/boost/leaf/serialization/json_encoder_boost.hpp deleted file mode 100644 index 70bea67..0000000 --- a/include/boost/leaf/serialization/json_encoder_boost.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef BOOST_LEAF_SERIALIZATION_JSON_ENCODER_BOOST_HPP_INCLUDED -#define BOOST_LEAF_SERIALIZATION_JSON_ENCODER_BOOST_HPP_INCLUDED - -// Copyright 2018-2026 Emil Dotchevski and Reverge Studios, Inc. -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#include - -namespace boost { namespace json { - -class value; - -template -void value_from(T &&, value &); - -} } - -namespace boost { namespace leaf { - -namespace serialization -{ - template - struct json_encoder_boost_ - { - Value & v_; - - template ::value>::type> - friend void output(Encoder & e, T const & x, Deprioritize...) - { - boost::json::value_from(x, e.v_); - } - - template - friend void output_at(json_encoder_boost_ & e, T const & x, char const * name) - { - if( e.v_.is_null() ) - e.v_.emplace_object(); - json_encoder_boost_ nested{e.v_.as_object()[name]}; - output(nested, x); - } - }; - - using json_encoder_boost = json_encoder_boost_<>; -} - -} } - -#endif diff --git a/include/boost/leaf/serialization/json_encoder_nlohmann.hpp b/include/boost/leaf/serialization/nlohmann_json_encoder.hpp similarity index 64% rename from include/boost/leaf/serialization/json_encoder_nlohmann.hpp rename to include/boost/leaf/serialization/nlohmann_json_encoder.hpp index 161fd1c..60b616f 100644 --- a/include/boost/leaf/serialization/json_encoder_nlohmann.hpp +++ b/include/boost/leaf/serialization/nlohmann_json_encoder.hpp @@ -1,5 +1,5 @@ -#ifndef BOOST_LEAF_SERIALIZATION_JSON_ENCODER_NLOHMANN_HPP_INCLUDED -#define BOOST_LEAF_SERIALIZATION_JSON_ENCODER_NLOHMANN_HPP_INCLUDED +#ifndef BOOST_LEAF_SERIALIZATION_NLOHMANN_JSON_ENCODER_HPP_INCLUDED +#define BOOST_LEAF_SERIALIZATION_NLOHMANN_JSON_ENCODER_HPP_INCLUDED // Copyright 2018-2026 Emil Dotchevski and Reverge Studios, Inc. // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -12,20 +12,20 @@ namespace boost { namespace leaf { namespace serialization { template - struct json_encoder_nlohmann + struct nlohmann_json_encoder { Json & j_; template - friend auto output(json_encoder_nlohmann & e, T const & x) -> decltype(to_json(std::declval(), x), void()) + friend auto output(nlohmann_json_encoder & e, T const & x) -> decltype(to_json(std::declval(), x), void()) { to_json(e.j_, x); } template - friend void output_at(json_encoder_nlohmann & e, T const & x, char const * name) + friend void output_at(nlohmann_json_encoder & e, T const & x, char const * name) { - json_encoder_nlohmann nested{e.j_[name]}; + nlohmann_json_encoder nested{e.j_[name]}; output(nested, x); } }; diff --git a/meson.build b/meson.build index 808cef6..7e28a17 100644 --- a/meson.build +++ b/meson.build @@ -141,11 +141,11 @@ if option_enable_unit_tests 'handle_basic_test', 'handle_some_other_result_test', 'handle_some_test', - 'json_encoder_nlohmann_test', 'match_member_test', 'match_test', 'match_value_test', 'multiple_errors_test', + 'nlohmann_json_encoder_test', 'on_error_accumulate_basic_test', 'on_error_accumulate_nested_error_exception_test', 'on_error_accumulate_nested_error_result_test', @@ -173,7 +173,6 @@ if option_enable_unit_tests 'on_error_preload_nested_success_exception_test', 'on_error_preload_nested_success_result_test', 'optional_test', - 'type_name_test', 'print_test', 'result_bad_result_test', 'result_implicit_conversion_test', @@ -191,6 +190,7 @@ if option_enable_unit_tests 'try_catch_system_error_test', 'try_catch_test', 'try_exception_and_result_test', + 'type_name_test', ] if option_boost_available and option_exceptions tests += [ @@ -224,7 +224,7 @@ if option_enable_unit_tests '_hpp_on_error_test', '_hpp_pred_test', '_hpp_result_test', - '_hpp_serialization_json_encoder_nlohmann_test', + '_hpp_serialization_nlohmann_json_encoder_test', '_hpp_to_variant_test', ] foreach t : header_tests diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 5e351fe..108d4b8 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -44,14 +44,15 @@ compile _hpp_leaf_test.cpp ; compile _hpp_on_error_test.cpp ; compile _hpp_pred_test.cpp ; compile _hpp_result_test.cpp ; -compile _hpp_serialization_json_encoder_nlohmann_test.cpp ; -compile _hpp_serialization_json_encoder_boost_test.cpp ; +compile _hpp_serialization_boost_json_encoder_test.cpp ; +compile _hpp_serialization_nlohmann_json_encoder_test.cpp ; compile _hpp_to_variant_test.cpp ; -run boost_exception_test.cpp ; run BOOST_LEAF_ASSIGN_test.cpp ; run BOOST_LEAF_AUTO_test.cpp ; run BOOST_LEAF_CHECK_test.cpp ; +run boost_exception_test.cpp ; +run boost_json_encoder_test.cpp /boost/json//boost_json : : : off:no off:no ; run capture_exception_async_test.cpp ; run capture_exception_result_async_test.cpp ; run capture_exception_result_unload_test.cpp ; @@ -85,12 +86,11 @@ run handle_all_test.cpp ; run handle_basic_test.cpp ; run handle_some_other_result_test.cpp ; run handle_some_test.cpp ; -run json_encoder_nlohmann_test.cpp : : : clang,linux,2b:no clang,linux,23:no ; -run json_encoder_boost_test.cpp /boost/json//boost_json : : : off:no off:no ; run match_member_test.cpp ; run match_test.cpp ; run match_value_test.cpp ; run multiple_errors_test.cpp ; +run nlohmann_json_encoder_test.cpp : : : clang,linux,2b:no clang,linux,23:no ; run on_error_accumulate_basic_test.cpp ; run on_error_accumulate_nested_error_exception_test.cpp ; run on_error_accumulate_nested_error_result_test.cpp ; @@ -118,7 +118,6 @@ run on_error_preload_nested_new_error_result_test.cpp ; run on_error_preload_nested_success_exception_test.cpp ; run on_error_preload_nested_success_result_test.cpp ; run optional_test.cpp ; -run type_name_test.cpp ; run print_test.cpp ; run result_bad_result_test.cpp ; run result_implicit_conversion_test.cpp ; @@ -136,6 +135,7 @@ run try_catch_error_id_test.cpp ; run try_catch_system_error_test.cpp ; run try_catch_test.cpp ; run try_exception_and_result_test.cpp ; +run type_name_test.cpp ; lib so_dll_lib1 : so_dll_lib1.cpp : shared hidden windows:BOOST_LEAF_CFG_WIN32=2 : : windows:BOOST_LEAF_CFG_WIN32=2 ; lib so_dll_lib2 : so_dll_lib2.cpp : shared hidden windows:BOOST_LEAF_CFG_WIN32=2 : : windows:BOOST_LEAF_CFG_WIN32=2 ; @@ -161,12 +161,12 @@ compile-fail _compile-fail-error_obj_ptr.cpp ; compile-fail _compile-fail-exception_1.cpp ; compile-fail _compile-fail-exception_2.cpp ; compile-fail _compile-fail-new_error.cpp ; -compile-fail _compile-fail-serialization_json_encoder_boost.cpp ; -compile-fail _compile-fail-serialization_json_encoder_nlohmann.cpp ; compile-fail _compile-fail-result_1.cpp ; compile-fail _compile-fail-result_2.cpp ; compile-fail _compile-fail-result_3.cpp ; compile-fail _compile-fail-result_4.cpp ; +compile-fail _compile-fail-serialization_boost_json_encoder.cpp ; +compile-fail _compile-fail-serialization_nlohmann_json_encoder.cpp ; exe try_capture_all_exceptions : ../example/try_capture_all_exceptions.cpp : single:no off:no leaf_debug_capture0:no leaf_release_capture0:no ; exe try_capture_all_result : ../example/try_capture_all_result.cpp : single:no leaf_debug_capture0:no leaf_release_capture0:no leaf_debug_embedded:no leaf_release_embedded:no ; diff --git a/test/_compile-fail-serialization_json_encoder_boost.cpp b/test/_compile-fail-serialization_boost_json_encoder.cpp similarity index 77% rename from test/_compile-fail-serialization_json_encoder_boost.cpp rename to test/_compile-fail-serialization_boost_json_encoder.cpp index a807543..00a8b95 100644 --- a/test/_compile-fail-serialization_json_encoder_boost.cpp +++ b/test/_compile-fail-serialization_boost_json_encoder.cpp @@ -2,7 +2,7 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#include +#include #include struct no_tag_invoke {}; @@ -13,6 +13,6 @@ struct e_no_tag_invoke }; boost::json::value v; -boost::leaf::serialization::json_encoder_boost e{v}; +boost::leaf::serialization::boost_json_encoder e{v}; e_no_tag_invoke x; auto y = (output(e, x), 0); diff --git a/test/_compile-fail-serialization_json_encoder_nlohmann.cpp b/test/_compile-fail-serialization_nlohmann_json_encoder.cpp similarity index 75% rename from test/_compile-fail-serialization_json_encoder_nlohmann.cpp rename to test/_compile-fail-serialization_nlohmann_json_encoder.cpp index 7315320..767a851 100644 --- a/test/_compile-fail-serialization_json_encoder_nlohmann.cpp +++ b/test/_compile-fail-serialization_nlohmann_json_encoder.cpp @@ -2,7 +2,7 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#include +#include #include "nlohmann/json.hpp" struct no_to_json {}; @@ -13,6 +13,6 @@ struct e_no_to_json }; nlohmann::json j; -boost::leaf::serialization::json_encoder_nlohmann w{j}; +boost::leaf::serialization::nlohmann_json_encoder w{j}; e_no_to_json e; auto x = (output(w, e), 0); diff --git a/test/_hpp_serialization_json_encoder_boost_test.cpp b/test/_hpp_serialization_boost_json_encoder_test.cpp similarity index 67% rename from test/_hpp_serialization_json_encoder_boost_test.cpp rename to test/_hpp_serialization_boost_json_encoder_test.cpp index 82336ed..b36add4 100644 --- a/test/_hpp_serialization_json_encoder_boost_test.cpp +++ b/test/_hpp_serialization_boost_json_encoder_test.cpp @@ -2,6 +2,6 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#include -#include +#include +#include int main() { return 0; } diff --git a/test/_hpp_serialization_json_encoder_nlohmann_test.cpp b/test/_hpp_serialization_nlohmann_json_encoder_test.cpp similarity index 66% rename from test/_hpp_serialization_json_encoder_nlohmann_test.cpp rename to test/_hpp_serialization_nlohmann_json_encoder_test.cpp index 340ad25..3308959 100644 --- a/test/_hpp_serialization_json_encoder_nlohmann_test.cpp +++ b/test/_hpp_serialization_nlohmann_json_encoder_test.cpp @@ -2,6 +2,6 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -#include -#include +#include +#include int main() { return 0; } diff --git a/test/json_encoder_boost_test.cpp b/test/boost_json_encoder_test.cpp similarity index 94% rename from test/json_encoder_boost_test.cpp rename to test/boost_json_encoder_test.cpp index 8250072..b570910 100644 --- a/test/json_encoder_boost_test.cpp +++ b/test/boost_json_encoder_test.cpp @@ -10,14 +10,13 @@ # include # include # include -# include +# include #endif #include #include #include #include -#include #if BOOST_LEAF_CFG_STD_SYSTEM_ERROR # include #endif @@ -28,7 +27,7 @@ namespace leaf = boost::leaf; -using output_encoder = leaf::serialization::json_encoder_boost; +using output_encoder = leaf::serialization::boost_json_encoder; namespace boost { namespace leaf { @@ -38,7 +37,7 @@ template void serialize(Handle & h, T const & x, char const * name) { h.dispatch( - [&](json_encoder_boost & e) { output_at(e, x, name); } + [&](boost_json_encoder & e) { output_at(e, x, name); } ); } @@ -77,11 +76,6 @@ struct my_error } }; -struct my_error_with_vector -{ - std::vector value; -}; - leaf::result fail() { return BOOST_LEAF_NEW_ERROR( @@ -93,7 +87,6 @@ leaf::result fail() 42, my_error<1>{1, "error one"}, my_error<2>{2, "error two"}, - my_error_with_vector{{10, 20, 30}}, leaf::e_errno{ENOENT}, leaf::e_api_function{"my_api_function"} ); } @@ -110,7 +103,6 @@ void leaf_throw() 42, my_error<1>{1, "error one"}, my_error<2>{2, "error two"}, - my_error_with_vector{{10, 20, 30}}, leaf::e_errno{ENOENT}, leaf::e_api_function{"my_api_function"} ); } @@ -126,7 +118,6 @@ void throw_() 42, my_error<1>{1, "error one"}, my_error<2>{2, "error two"}, - my_error_with_vector{{10, 20, 30}}, leaf::e_errno{ENOENT}, leaf::e_api_function{"my_api_function"} ); throw my_exception{}; @@ -176,13 +167,6 @@ void check_diagnostic_details(boost::json::value const & j, bool has_source_loca BOOST_TEST_EQ(boost::json::value_to(e2j.at("code")), 2); BOOST_TEST_EQ(boost::json::value_to(e2j.at("message")), "error two"); - auto const & vj = j.at("my_error_with_vector"); - BOOST_TEST(vj.is_array()); - BOOST_TEST_EQ(vj.as_array().size(), 3); - BOOST_TEST_EQ(boost::json::value_to(vj.as_array()[0]), 10); - BOOST_TEST_EQ(boost::json::value_to(vj.as_array()[1]), 20); - BOOST_TEST_EQ(boost::json::value_to(vj.as_array()[2]), 30); - auto const & ej = j.at("boost::leaf::e_errno"); BOOST_TEST_EQ(boost::json::value_to(ej.at("errno")), ENOENT); BOOST_TEST(!boost::json::value_to(ej.at("strerror")).empty()); diff --git a/test/json_encoder_nlohmann_test.cpp b/test/nlohmann_json_encoder_test.cpp similarity index 97% rename from test/json_encoder_nlohmann_test.cpp rename to test/nlohmann_json_encoder_test.cpp index 11317ca..acbe510 100644 --- a/test/json_encoder_nlohmann_test.cpp +++ b/test/nlohmann_json_encoder_test.cpp @@ -10,7 +10,7 @@ # include # include # include -# include +# include #endif #include "nlohmann/json.hpp" @@ -28,7 +28,7 @@ namespace leaf = boost::leaf; -using output_encoder = leaf::serialization::json_encoder_nlohmann; +using output_encoder = leaf::serialization::nlohmann_json_encoder; namespace boost { namespace leaf { @@ -38,8 +38,8 @@ template void serialize(Handle & h, T const & x, char const * name) { h.dispatch( - [&](json_encoder_nlohmann & e) { output_at(e, x, name); }, - [&](json_encoder_nlohmann & e) { output_at(e, x, name); } + [&](nlohmann_json_encoder & e) { output_at(e, x, name); }, + [&](nlohmann_json_encoder & e) { output_at(e, x, name); } ); }