diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index 28de450280..bdeae78f0c 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -862,6 +862,15 @@ class json_pointer { return *this == json_pointer(rhs); } + + /// @brief compares JSON pointer and string for less-than + template + friend bool operator<(json_pointer const& lhs, + json_pointer const& rhs) noexcept + { + return lhs.reference_tokens < rhs.reference_tokens; + } + #else /// @brief compares two JSON pointers for equality /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ @@ -904,6 +913,12 @@ class json_pointer // NOLINTNEXTLINE(readability-redundant-declaration) friend bool operator!=(const StringType& lhs, const json_pointer& rhs); + + /// @brief compares string and JSON pointer for less-than + template + // NOLINTNEXTLINE(readability-redundant-declaration) + friend bool operator<(const StringType& lhs, + const json_pointer& rhs); #endif private: @@ -958,6 +973,13 @@ inline bool operator!=(const StringType& lhs, { return !(lhs == rhs); } + +template +inline bool operator<(const json_pointer& lhs, + const json_pointer& rhs) noexcept +{ + return lhs.reference_tokens < rhs.reference_tokens; +} #endif NLOHMANN_JSON_NAMESPACE_END diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index beee0136c5..3bf1b92fba 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -14464,6 +14464,15 @@ class json_pointer { return *this == json_pointer(rhs); } + + /// @brief compares JSON pointer and string for less-than + template + friend bool operator<(json_pointer const& lhs, + json_pointer const& rhs) noexcept + { + return lhs.reference_tokens < rhs.reference_tokens; + } + #else /// @brief compares two JSON pointers for equality /// @sa https://json.nlohmann.me/api/json_pointer/operator_eq/ @@ -14506,6 +14515,12 @@ class json_pointer // NOLINTNEXTLINE(readability-redundant-declaration) friend bool operator!=(const StringType& lhs, const json_pointer& rhs); + + /// @brief compares string and JSON pointer for less-than + template + // NOLINTNEXTLINE(readability-redundant-declaration) + friend bool operator<(const StringType& lhs, + const json_pointer& rhs); #endif private: @@ -14560,6 +14575,13 @@ inline bool operator!=(const StringType& lhs, { return !(lhs == rhs); } + +template +inline bool operator<(const json_pointer& lhs, + const json_pointer& rhs) noexcept +{ + return lhs.reference_tokens < rhs.reference_tokens; +} #endif NLOHMANN_JSON_NAMESPACE_END