diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index 5d28cdf20..e0b773330 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -53,13 +53,12 @@ template , std::pair emplace(const key_type& key, T&& t) { - for (auto it = this->begin(); it != this->end(); ++it) + auto iter = this->find(key); + if (iter != this->end()) { - if (m_compare(it->first, key)) - { - return {it, false}; - } + return {iter, false}; } + Container::emplace_back(key, std::forward(t)); return {std::prev(this->end()), true}; }