Allow comparing different json_pointers
This commit is contained in:
parent
03dbf3ed97
commit
f5f975a48c
@ -836,11 +836,10 @@ class json_pointer
|
|||||||
|
|
||||||
@exceptionsafety No-throw guarantee: this function never throws exceptions.
|
@exceptionsafety No-throw guarantee: this function never throws exceptions.
|
||||||
*/
|
*/
|
||||||
friend bool operator==(json_pointer const& lhs,
|
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
|
||||||
json_pointer const& rhs) noexcept
|
// NOLINTNEXTLINE(readability-redundant-declaration)
|
||||||
{
|
friend bool operator==(json_pointer<RefStringTypeLhs> const& lhs,
|
||||||
return lhs.reference_tokens == rhs.reference_tokens;
|
json_pointer<RefStringTypeRhs> const& rhs) noexcept;
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief compares two JSON pointers for inequality
|
@brief compares two JSON pointers for inequality
|
||||||
@ -853,13 +852,27 @@ class json_pointer
|
|||||||
|
|
||||||
@exceptionsafety No-throw guarantee: this function never throws exceptions.
|
@exceptionsafety No-throw guarantee: this function never throws exceptions.
|
||||||
*/
|
*/
|
||||||
friend bool operator!=(json_pointer const& lhs,
|
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
|
||||||
json_pointer const& rhs) noexcept
|
// NOLINTNEXTLINE(readability-redundant-declaration)
|
||||||
{
|
friend bool operator!=(json_pointer<RefStringTypeLhs> const& lhs,
|
||||||
return !(lhs == rhs);
|
json_pointer<RefStringTypeRhs> const& rhs) noexcept;
|
||||||
}
|
|
||||||
|
|
||||||
/// the reference tokens
|
/// the reference tokens
|
||||||
std::vector<string_t> reference_tokens;
|
std::vector<string_t> reference_tokens;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// functions cannot be defined inside class due to ODR violations
|
||||||
|
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
|
||||||
|
inline bool operator==(json_pointer<RefStringTypeLhs> const& lhs,
|
||||||
|
json_pointer<RefStringTypeRhs> const& rhs) noexcept
|
||||||
|
{
|
||||||
|
return lhs.reference_tokens == rhs.reference_tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
|
||||||
|
inline bool operator!=(json_pointer<RefStringTypeLhs> const& lhs,
|
||||||
|
json_pointer<RefStringTypeRhs> const& rhs) noexcept
|
||||||
|
{
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
} // namespace nlohmann
|
} // namespace nlohmann
|
||||||
|
|||||||
@ -13301,11 +13301,10 @@ class json_pointer
|
|||||||
|
|
||||||
@exceptionsafety No-throw guarantee: this function never throws exceptions.
|
@exceptionsafety No-throw guarantee: this function never throws exceptions.
|
||||||
*/
|
*/
|
||||||
friend bool operator==(json_pointer const& lhs,
|
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
|
||||||
json_pointer const& rhs) noexcept
|
// NOLINTNEXTLINE(readability-redundant-declaration)
|
||||||
{
|
friend bool operator==(json_pointer<RefStringTypeLhs> const& lhs,
|
||||||
return lhs.reference_tokens == rhs.reference_tokens;
|
json_pointer<RefStringTypeRhs> const& rhs) noexcept;
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief compares two JSON pointers for inequality
|
@brief compares two JSON pointers for inequality
|
||||||
@ -13318,15 +13317,29 @@ class json_pointer
|
|||||||
|
|
||||||
@exceptionsafety No-throw guarantee: this function never throws exceptions.
|
@exceptionsafety No-throw guarantee: this function never throws exceptions.
|
||||||
*/
|
*/
|
||||||
friend bool operator!=(json_pointer const& lhs,
|
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
|
||||||
json_pointer const& rhs) noexcept
|
// NOLINTNEXTLINE(readability-redundant-declaration)
|
||||||
{
|
friend bool operator!=(json_pointer<RefStringTypeLhs> const& lhs,
|
||||||
return !(lhs == rhs);
|
json_pointer<RefStringTypeRhs> const& rhs) noexcept;
|
||||||
}
|
|
||||||
|
|
||||||
/// the reference tokens
|
/// the reference tokens
|
||||||
std::vector<string_t> reference_tokens;
|
std::vector<string_t> reference_tokens;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// functions cannot be defined inside class due to ODR violations
|
||||||
|
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
|
||||||
|
inline bool operator==(json_pointer<RefStringTypeLhs> const& lhs,
|
||||||
|
json_pointer<RefStringTypeRhs> const& rhs) noexcept
|
||||||
|
{
|
||||||
|
return lhs.reference_tokens == rhs.reference_tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename RefStringTypeLhs, typename RefStringTypeRhs>
|
||||||
|
inline bool operator!=(json_pointer<RefStringTypeLhs> const& lhs,
|
||||||
|
json_pointer<RefStringTypeRhs> const& rhs) noexcept
|
||||||
|
{
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
} // namespace nlohmann
|
} // namespace nlohmann
|
||||||
|
|
||||||
// #include <nlohmann/detail/json_ref.hpp>
|
// #include <nlohmann/detail/json_ref.hpp>
|
||||||
|
|||||||
@ -661,6 +661,15 @@ TEST_CASE("JSON pointers")
|
|||||||
CHECK(ptr.to_string() == "/object/~1");
|
CHECK(ptr.to_string() == "/object/~1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("equality comparison")
|
||||||
|
{
|
||||||
|
auto ptr1 = json::json_pointer("/foo/bar");
|
||||||
|
auto ptr2 = json::json_pointer("/foo/bar");
|
||||||
|
|
||||||
|
CHECK(ptr1 == ptr2);
|
||||||
|
CHECK_FALSE(ptr1 != ptr2);
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("backwards compatibility and mixing")
|
SECTION("backwards compatibility and mixing")
|
||||||
{
|
{
|
||||||
json j = R"(
|
json j = R"(
|
||||||
@ -695,5 +704,10 @@ TEST_CASE("JSON pointers")
|
|||||||
|
|
||||||
CHECK(j.value(ptr, "x") == j.value(ptr_j, "x"));
|
CHECK(j.value(ptr, "x") == j.value(ptr_j, "x"));
|
||||||
CHECK(j.value(ptr, "x") == j.value(ptr_oj, "x"));
|
CHECK(j.value(ptr, "x") == j.value(ptr_oj, "x"));
|
||||||
|
|
||||||
|
CHECK(ptr == ptr_j);
|
||||||
|
CHECK(ptr == ptr_oj);
|
||||||
|
CHECK_FALSE(ptr != ptr_j);
|
||||||
|
CHECK_FALSE(ptr != ptr_oj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user