Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions include/nlohmann/ordered_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,20 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
return Container::end();
}

template<class KeyType, detail::enable_if_t<
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
const_iterator find(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward)
{
for (auto it = this->begin(); it != this->end(); ++it)
{
if (m_compare(it->first, key))
{
return it;
}
}
return Container::end();
}

std::pair<iterator, bool> insert( value_type&& value )
{
return emplace(value.first, std::move(value.second));
Expand Down
14 changes: 14 additions & 0 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20331,6 +20331,20 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
return Container::end();
}

template<class KeyType, detail::enable_if_t<
detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
const_iterator find(KeyType && key) const // NOLINT(cppcoreguidelines-missing-std-forward)
{
for (auto it = this->begin(); it != this->end(); ++it)
{
if (m_compare(it->first, key))
{
return it;
}
}
return Container::end();
}

std::pair<iterator, bool> insert( value_type&& value )
{
return emplace(value.first, std::move(value.second));
Expand Down
5 changes: 5 additions & 0 deletions tests/src/unit-ordered_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) == om.begin());
CHECK(com.find(std::string_view("eins")) == com.begin());
#endif
}

SECTION("insert")
Expand Down
Loading