From 5598ec9a98b6ba020d841535c12170336fe35d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Sun, 16 Nov 2025 21:26:32 +0300 Subject: [PATCH] mdbx++: add three-way comparison for `mdbx::slice`, `mdbx::buffer` and `mdbx::pair`. --- mdbx.h++ | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mdbx.h++ b/mdbx.h++ index ba5a4143..6a44a6f8 100644 --- a/mdbx.h++ +++ b/mdbx.h++ @@ -1000,6 +1000,9 @@ struct LIBMDBX_API_TYPE slice : public ::MDBX_val { friend MDBX_CXX14_CONSTEXPR bool operator<=(const slice &a, const slice &b) noexcept; friend MDBX_CXX14_CONSTEXPR bool operator>=(const slice &a, const slice &b) noexcept; friend MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a, const slice &b) noexcept; +#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L + friend MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept; +#endif /* __cpp_impl_three_way_comparison */ /// \brief Checks the slice is not refers to null address or has zero length. MDBX_CXX11_CONSTEXPR bool is_valid() const noexcept { return !(iov_base == nullptr && iov_len != 0); } @@ -2756,6 +2759,9 @@ struct pair { friend MDBX_CXX14_CONSTEXPR bool operator<=(const pair &a, const pair &b) noexcept; friend MDBX_CXX14_CONSTEXPR bool operator>=(const pair &a, const pair &b) noexcept; friend MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, const pair &b) noexcept; +#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L + friend MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept; +#endif /* __cpp_impl_three_way_comparison */ }; /// \brief Combines pair of slices for key and value with boolean flag to @@ -5014,6 +5020,12 @@ MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool operator!=(const slice &a, return slice::compare_fast(a, b) != 0; } +#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L +MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const slice &a, const slice &b) noexcept { + return slice::compare_lexicographically(a, b); +} +#endif /* __cpp_impl_three_way_comparison */ + template inline string slice::as_hex_string(bool uppercase, unsigned wrap_width, const ALLOCATOR &allocator) const { return to_hex(*this, uppercase, wrap_width).as_string(allocator); @@ -5112,6 +5124,12 @@ MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR bool operator!=(const pair &a, c memcmp(a.value.data(), b.value.data(), a.value.length()) != 0; } +#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L +MDBX_NOTHROW_PURE_FUNCTION MDBX_CXX14_CONSTEXPR auto operator<=>(const pair &a, const pair &b) noexcept { + return pair::compare_lexicographically(a, b); +} +#endif /* __cpp_impl_three_way_comparison */ + //------------------------------------------------------------------------------ template