From 53437add145e5a3f27d94c009748d978005d25a2 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 15 May 2026 10:01:38 +0200 Subject: [PATCH] :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 5ba0da18f..ab035df7d 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 65b3b3459..199a3bcbe 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 76ed4f34f..d01a23a06 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")