[libcxx-commits] [libcxx] [libc++] Refactor __tuple_like and __pair_like (PR #85206)

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 20 03:38:50 PDT 2024


================
@@ -27,29 +24,15 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 #if _LIBCPP_STD_VER >= 20
 
 template <class _Tp>
-struct __tuple_like_impl : false_type {};
+inline constexpr bool __is_ranges_subrange_v = false;
 
-template <class... _Tp>
-struct __tuple_like_impl<tuple<_Tp...> > : true_type {};
-
-template <class _T1, class _T2>
-struct __tuple_like_impl<pair<_T1, _T2> > : true_type {};
-
-template <class _Tp, size_t _Size>
-struct __tuple_like_impl<array<_Tp, _Size> > : true_type {};
-
-template <class _Ip, class _Sp, ranges::subrange_kind _Kp>
-struct __tuple_like_impl<ranges::subrange<_Ip, _Sp, _Kp> > : true_type {};
-
-#  if _LIBCPP_STD_VER >= 26
+template <class _Iter, class _Sent, ranges::subrange_kind _Kind>
+inline constexpr bool __is_ranges_subrange_v<ranges::subrange<_Iter, _Sent, _Kind>> = true;
 
 template <class _Tp>
-struct __tuple_like_impl<complex<_Tp>> : true_type {};
-
-#  endif
+concept __tuple_like = __tuple_like_no_subrange<_Tp> || __is_ranges_subrange_v<remove_cvref_t<_Tp>>;
 
-template <class _Tp>
-concept __tuple_like = __tuple_like_impl<remove_cvref_t<_Tp>>::value;
+// If the exposition-only type trait `pair-like` is required, you most likely want __pair_like_no_subrange.
----------------
mordante wrote:

Please explain why you most likely want this `__pair_like_no_subrange`. The commit message explains it, but in the future `__pair_like` might become useful, then this comment is misleading.

I also wonder whether it shouldn't be better to keep this in the `tuple_like` header. Putting it in a different header decreases its visibility.


https://github.com/llvm/llvm-project/pull/85206


More information about the libcxx-commits mailing list