From 53437add145e5a3f27d94c009748d978005d25a2 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 15 May 2026 10:01:38 +0200 Subject: [PATCH 1/4] :bug: add missing overload Signed-off-by: Niels Lohmann --- include/nlohmann/ordered_map.hpp | 14 ++++++++++++++ single_include/nlohmann/json.hpp | 16 ++++++++++++++++ tests/src/unit-ordered_map.cpp | 5 +++++ 3 files changed, 35 insertions(+) diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index 5ba0da18f9..ab035df7dd 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -340,6 +340,20 @@ template , return Container::end(); } + template::value, int> = 0> + const_iterator find(KeyType && key) const + { + for (auto it = this->begin(); it != this->end(); ++it) + { + if (m_compare(it->first, key)) + { + return it; + } + } + return Container::end(); + } + std::pair insert( value_type&& value ) { return emplace(value.first, std::move(value.second)); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 65b3b34592..199a3bcbef 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20331,6 +20331,22 @@ template , return Container::end(); } + /* + template::value, int> = 0> + const_iterator find(KeyType && key) const + { + for (auto it = this->begin(); it != this->end(); ++it) + { + if (m_compare(it->first, key)) + { + return it; + } + } + return Container::end(); + } + */ + std::pair insert( value_type&& value ) { return emplace(value.first, std::move(value.second)); diff --git a/tests/src/unit-ordered_map.cpp b/tests/src/unit-ordered_map.cpp index 76ed4f34f3..d01a23a063 100644 --- a/tests/src/unit-ordered_map.cpp +++ b/tests/src/unit-ordered_map.cpp @@ -269,6 +269,11 @@ TEST_CASE("ordered_map") CHECK(com.find("vier") == com.end()); CHECK(com.find(std::string("vier")) == com.end()); CHECK(com.find(vier) == com.end()); + +#ifdef JSON_HAS_CPP_17 + CHECK(om.find(std::string_view("eins")) == com.begin()); + CHECK(com.find(std::string_view("eins")) == com.begin()); +#endif } SECTION("insert") From f13cf31341d4328168cc548110730afe9f527ba3 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 15 May 2026 11:36:11 +0200 Subject: [PATCH 2/4] :art: fix amalgamation Signed-off-by: Niels Lohmann --- single_include/nlohmann/json.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 199a3bcbef..fd97a7b53c 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20331,7 +20331,6 @@ template , return Container::end(); } - /* template::value, int> = 0> const_iterator find(KeyType && key) const @@ -20345,7 +20344,6 @@ template , } return Container::end(); } - */ std::pair insert( value_type&& value ) { From b7b573f871999cc1781bf835a7dffd30ef6e39fa Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 18 May 2026 15:10:46 +0200 Subject: [PATCH 3/4] :bug: fix typo Signed-off-by: Niels Lohmann --- tests/src/unit-ordered_map.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/unit-ordered_map.cpp b/tests/src/unit-ordered_map.cpp index d01a23a063..f380a98690 100644 --- a/tests/src/unit-ordered_map.cpp +++ b/tests/src/unit-ordered_map.cpp @@ -271,7 +271,7 @@ TEST_CASE("ordered_map") CHECK(com.find(vier) == com.end()); #ifdef JSON_HAS_CPP_17 - CHECK(om.find(std::string_view("eins")) == com.begin()); + CHECK(om.find(std::string_view("eins")) == om.begin()); CHECK(com.find(std::string_view("eins")) == com.begin()); #endif } From 43ca4bfcb0bbc3af9faf5f334234974e6653d72b Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 18 May 2026 15:34:21 +0200 Subject: [PATCH 4/4] :rotating_light: fix warning Signed-off-by: Niels Lohmann --- include/nlohmann/ordered_map.hpp | 2 +- single_include/nlohmann/json.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index ab035df7dd..7b8cf70f4c 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -342,7 +342,7 @@ template , template::value, int> = 0> - const_iterator find(KeyType && key) const + const_iterator find(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) { for (auto it = this->begin(); it != this->end(); ++it) { diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index fd97a7b53c..b643608293 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20333,7 +20333,7 @@ template , template::value, int> = 0> - const_iterator find(KeyType && key) const + const_iterator find(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward) { for (auto it = this->begin(); it != this->end(); ++it) {