These appear to be noexcept-able.

Osama Abdelkader <[email protected]> 於 2025年10月18日 週六 下午10:50寫道:

> This fixes the C++23 compliance issue where std::tuple<> cannot be compared
> with other empty tuple-like types such as std::array<T, 0>.
>
> The operators correctly allow comparison with array<T, 0> even when T is
> not
> comparable, because empty tuple-like types don't compare element values.
>
> libstdc++-v3/ChangeLog:
>
>         PR libstdc++/119721
>         * include/std/tuple: Add tuple<> comparison operators for
>         empty tuple-like types.
>
> Signed-off-by: Osama Abdelkader <[email protected]>
> ---
> v2:
> - Replaced explicit array<T, 0> operators with generic tuple-like operators
> - Only operator== and operator<=> are provided
> - Operators work with any empty tuple-like type
> - No need for reversed argument order
> ---
>  libstdc++-v3/include/std/tuple | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>
> diff --git a/libstdc++-v3/include/std/tuple
> b/libstdc++-v3/include/std/tuple
> index 0ca616f1b..800f6e372 100644
> --- a/libstdc++-v3/include/std/tuple
> +++ b/libstdc++-v3/include/std/tuple
> @@ -2001,6 +2001,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>         tuple(allocator_arg_t, const _Alloc&, const tuple&) noexcept { }
>      };
>
> +#if __cpp_lib_tuple_like // >= C++23
> +  // Comparison operators for tuple<> with other empty tuple-like types
> +  // Note: These operators allow comparison with any empty tuple-like
> type,
> +  // including array<T, 0> and span<T, 0>, where T may not be comparable.
> +  // This is correct because empty tuple-like types don't compare
> elements.
> +  template<__tuple_like _UTuple>
> +    requires (!__is_tuple_v<_UTuple> && tuple_size_v<_UTuple> == 0)
> +  [[nodiscard]]
> +  constexpr bool
> +  operator==(const tuple<>&, const _UTuple&)
> +  { return true; }
> +
> +  template<__tuple_like _UTuple>
> +    requires (!__is_tuple_v<_UTuple> && tuple_size_v<_UTuple> == 0)
> +  constexpr strong_ordering
> +  operator<=>(const tuple<>&, const _UTuple&)
> +  { return strong_ordering::equal; }
> +#endif // C++23
> +
>  #if !(__cpp_concepts && __cpp_consteval && __cpp_conditional_explicit) //
> !C++20
>    /// Partial specialization, 2-element tuple.
>    /// Includes construction and assignment from a pair.
> --
> 2.43.0
>
>

Reply via email to