diff --git a/immer/extra/persist/json/json_with_pool.hpp b/immer/extra/persist/json/json_with_pool.hpp index 52f425a4..ea9fb401 100644 --- a/immer/extra/persist/json/json_with_pool.hpp +++ b/immer/extra/persist/json/json_with_pool.hpp @@ -463,9 +463,27 @@ auto to_json_with_pool(const T& value0) return os.str(); } -template -auto load_pools(std::istream& is, const ReloadPoolF& reload_pool) +template +auto load_pools(std::istream& is, const auto& wrap) { + const auto reload_pool = + [wrap](std::istream& is, Pools pools, bool ignore_pool_exceptions) { + auto restore = immer::util::istream_snapshot{is}; + const auto original_pools = pools; + pools.ignore_pool_exceptions = ignore_pool_exceptions; + auto ar = json_immer_input_archive{ + std::move(pools), wrap, is}; + /** + * NOTE: Critical to clear the pools before loading into it + * again. I hit a bug when pools contained a vector and every + * load would append to it, instead of replacing the contents. + */ + pools = {}; + ar(CEREAL_NVP(pools)); + pools.merge_previous(original_pools); + return pools; + }; + auto pools = Pools{}; if constexpr (detail::is_pool_empty()) { return pools; @@ -491,29 +509,12 @@ auto load_pools(std::istream& is, const ReloadPoolF& reload_pool) return pools; } -constexpr auto reload_pool = - [](std::istream& is, auto pools, bool ignore_pool_exceptions) { - using Pools = std::decay_t; - auto restore = util::istream_snapshot{is}; - pools.ignore_pool_exceptions = ignore_pool_exceptions; - auto ar = json_immer_input_archive{ - std::move(pools), is}; - /** - * NOTE: Critical to clear the pools before loading into it - * again. I hit a bug when pools contained a vector and every - * load would append to it, instead of replacing the contents. - */ - pools = {}; - ar(CEREAL_NVP(pools)); - return pools; - }; - template T from_json_with_pool(std::istream& is) { using Pools = std::decay_t())))>; - auto pools = load_pools(is, reload_pool); + auto pools = load_pools(is, boost::hana::id); auto ar = immer::persist::json_immer_input_archive; - auto restore = immer::util::istream_snapshot{is}; - const auto original_pools = pools; - pools.ignore_pool_exceptions = ignore_pool_exceptions; - auto ar = json_immer_input_archive{ - std::move(pools), wrap, is}; - /** - * NOTE: Critical to clear the pools before loading into it - * again. I hit a bug when pools contained a vector and every - * load would append to it, instead of replacing the contents. - */ - pools = {}; - ar(CEREAL_NVP(pools)); - pools.merge_previous(original_pools); - return pools; - }; -}; - template T from_json_with_auto_pool(std::istream& is, const PoolsTypes& pools_types) { @@ -231,7 +209,7 @@ T from_json_with_auto_pool(std::istream& is, const PoolsTypes& pools_types) using Pools = std::decay_t; - auto pools = load_pools(is, reload_pool_auto(wrap)); + auto pools = load_pools(is, wrap); auto ar = json_immer_input_archive; - auto restore = immer::util::istream_snapshot{is}; - pools.ignore_pool_exceptions = ignore_pool_exceptions; - auto ar = immer::persist::json_immer_input_archive< - cereal::XMLInputArchive, - Pools, - decltype(wrap)>{std::move(pools), wrap, is}; - /** - * NOTE: Critical to clear the pools before loading into it - * again. I hit a bug when pools contained a vector and every - * load would append to it, instead of replacing the contents. - */ - pools = {}; - ar(CEREAL_NVP(pools)); - return pools; - }; - }; - constexpr auto from_xml = [reload_pool_xml](const std::string& str, - auto& value0, - const auto& names, - const auto& wrap) { + constexpr auto from_xml = [](const std::string& str, + auto& value0, + const auto& names, + const auto& wrap) { auto is = std::istringstream{str}; using Pools = std::decay_t< decltype(immer::persist::detail::generate_input_pools(names))>; auto pools = - immer::persist::load_pools(is, reload_pool_xml(wrap)); + immer::persist::load_pools( + is, wrap); auto ar = immer::persist::json_immer_input_archive< cereal::XMLInputArchive,