From 972c15f26e0e5a5042d0d45c436c941bd0d77028 Mon Sep 17 00:00:00 2001 From: Krylov Yaroslav Date: Mon, 7 Dec 2020 20:15:41 +0300 Subject: [PATCH] ordered_map::insert(InputIt first, InputIt last) is added --- include/nlohmann/ordered_map.hpp | 13 +++++++++++++ single_include/nlohmann/json.hpp | 13 +++++++++++++ test/src/unit-ordered_json.cpp | 4 ++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index 7dd644543..330677c4d 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -168,6 +168,19 @@ template , Container::push_back(value); return {--this->end(), true}; } + + template + using require_input_iter = typename std::enable_if::iterator_category, + std::input_iterator_tag>::value>::type; + + template> + void insert(InputIt first, InputIt last) + { + for (auto it = first; it != last; ++it) + { + insert(*it); + } + } }; } // namespace nlohmann diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index e821c79a3..4caae0560 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -16634,6 +16634,19 @@ template , Container::push_back(value); return {--this->end(), true}; } + + template + using require_input_iter = typename std::enable_if::iterator_category, + std::input_iterator_tag>::value>::type; + + template> + void insert(InputIt first, InputIt last) + { + for (auto it = first; it != last; ++it) + { + insert(*it); + } + } }; } // namespace nlohmann diff --git a/test/src/unit-ordered_json.cpp b/test/src/unit-ordered_json.cpp index 92a5b9882..9bd1187e4 100644 --- a/test/src/unit-ordered_json.cpp +++ b/test/src/unit-ordered_json.cpp @@ -76,7 +76,7 @@ TEST_CASE("ordered_json") CHECK(multi_ordered.dump() == "{\"z\":1,\"m\":2,\"y\":4}"); CHECK(multi_ordered.erase("m") == 1); CHECK(multi_ordered.dump() == "{\"z\":1,\"y\":4}"); - + // Ranged insert test. // It seems that values shouldn't be overwritten. Only new values are added json j1 {{"c", 1}, {"b", 2}, {"a", 3}}; @@ -84,7 +84,7 @@ TEST_CASE("ordered_json") j1.insert( j2.cbegin(), j2.cend() ); CHECK(j1.size() == 4); CHECK(j1.dump() == "{\"a\":3,\"b\":2,\"c\":1,\"d\":42}"); - + ordered_json oj1 {{"c", 1}, {"b", 2}, {"a", 3}}; const ordered_json oj2 {{"c", 77}, {"d", 42}, {"a", 4}}; oj1.insert( oj2.cbegin(), oj2.cend() );