Replace == with key_compare in ordered_map

This commit is contained in:
Florian Albrechtskirchinger 2022-03-03 12:00:47 +01:00
parent fbcd541906
commit c126e1fd0c
4 changed files with 36 additions and 16 deletions

View File

@ -106,6 +106,12 @@
#endif #endif
#endif #endif
#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address)
#define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]]
#else
#define JSON_NO_UNIQUE_ADDRESS
#endif
// disable documentation warnings on clang // disable documentation warnings on clang
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic push #pragma clang diagnostic push

View File

@ -14,6 +14,7 @@
#undef NLOHMANN_BASIC_JSON_TPL #undef NLOHMANN_BASIC_JSON_TPL
#undef JSON_EXPLICIT #undef JSON_EXPLICIT
#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL #undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
#undef JSON_NO_UNIQUE_ADDRESS
#ifndef JSON_TEST_KEEP_MACROS #ifndef JSON_TEST_KEEP_MACROS
#undef JSON_CATCH #undef JSON_CATCH

View File

@ -47,7 +47,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return {it, false}; return {it, false};
} }
@ -70,7 +70,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return it->second; return it->second;
} }
@ -83,7 +83,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return it->second; return it->second;
} }
@ -96,7 +96,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
// Since we cannot move const Keys, re-construct them in place // Since we cannot move const Keys, re-construct them in place
for (auto next = it; ++next != this->end(); ++it) for (auto next = it; ++next != this->end(); ++it)
@ -168,7 +168,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return 1; return 1;
} }
@ -180,7 +180,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return it; return it;
} }
@ -192,7 +192,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return it; return it;
} }
@ -209,7 +209,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == value.first) if (m_compare(it->first, value.first))
{ {
return {it, false}; return {it, false};
} }
@ -230,6 +230,9 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
insert(*it); insert(*it);
} }
} }
private:
JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare();
}; };
} // namespace nlohmann } // namespace nlohmann

View File

@ -2411,6 +2411,12 @@ using is_detected_convertible =
#endif #endif
#endif #endif
#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address)
#define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]]
#else
#define JSON_NO_UNIQUE_ADDRESS
#endif
// disable documentation warnings on clang // disable documentation warnings on clang
#if defined(__clang__) #if defined(__clang__)
#pragma clang diagnostic push #pragma clang diagnostic push
@ -17359,7 +17365,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return {it, false}; return {it, false};
} }
@ -17382,7 +17388,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return it->second; return it->second;
} }
@ -17395,7 +17401,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return it->second; return it->second;
} }
@ -17408,7 +17414,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
// Since we cannot move const Keys, re-construct them in place // Since we cannot move const Keys, re-construct them in place
for (auto next = it; ++next != this->end(); ++it) for (auto next = it; ++next != this->end(); ++it)
@ -17480,7 +17486,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return 1; return 1;
} }
@ -17492,7 +17498,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return it; return it;
} }
@ -17504,7 +17510,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == key) if (m_compare(it->first, key))
{ {
return it; return it;
} }
@ -17521,7 +17527,7 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
{ {
for (auto it = this->begin(); it != this->end(); ++it) for (auto it = this->begin(); it != this->end(); ++it)
{ {
if (it->first == value.first) if (m_compare(it->first, value.first))
{ {
return {it, false}; return {it, false};
} }
@ -17542,6 +17548,9 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
insert(*it); insert(*it);
} }
} }
private:
JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare();
}; };
} // namespace nlohmann } // namespace nlohmann
@ -22293,6 +22302,7 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std
#undef NLOHMANN_BASIC_JSON_TPL #undef NLOHMANN_BASIC_JSON_TPL
#undef JSON_EXPLICIT #undef JSON_EXPLICIT
#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL #undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
#undef JSON_NO_UNIQUE_ADDRESS
#ifndef JSON_TEST_KEEP_MACROS #ifndef JSON_TEST_KEEP_MACROS
#undef JSON_CATCH #undef JSON_CATCH