mirror of
https://github.com/nlohmann/json.git
synced 2026-05-19 12:45:25 +00:00
Add missing overload to ordered_map::find (#5171)
* 🐛 add missing overload Signed-off-by: Niels Lohmann <mail@nlohmann.me> * 🎨 fix amalgamation Signed-off-by: Niels Lohmann <mail@nlohmann.me> * 🐛 fix typo Signed-off-by: Niels Lohmann <mail@nlohmann.me> * 🚨 fix warning Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -20468,6 +20468,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));
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user