[libcxx-commits] [PATCH] D132509: [libc++] Use _Lazy in tuple constructors

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 19 12:12:17 PDT 2023


ldionne updated this revision to Diff 557068.
ldionne marked an inline comment as done.
ldionne added a comment.

Rebase. Fix tests and comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132509/new/

https://reviews.llvm.org/D132509

Files:
  libcxx/include/tuple
  libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/recursion_depth.pass.cpp


Index: libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/recursion_depth.pass.cpp
===================================================================
--- libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/recursion_depth.pass.cpp
+++ libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/recursion_depth.pass.cpp
@@ -15,11 +15,31 @@
 #include <cassert>
 #include <utility>
 
+#include "test_macros.h"
+
+template <std::size_t I>
+struct constructible_from_integral_constant : std::integral_constant<std::size_t, I> { };
+
 template <std::size_t... I>
 constexpr void CreateTuple(std::index_sequence<I...>) {
-  std::tuple<decltype(I)...> tuple(I...);
-  assert(std::get<0>(tuple) == 0);
-  assert(std::get<sizeof...(I)-1>(tuple) == sizeof...(I)-1);
+  using LargeTuple = std::tuple<std::integral_constant<std::size_t, I>...>;
+  using TargetTuple = std::tuple<decltype(I)...>;
+  LargeTuple tuple(std::integral_constant<std::size_t, I>{}...);
+  assert(std::get<0>(tuple).value == 0);
+  assert(std::get<sizeof...(I)-1>(tuple).value == sizeof...(I)-1);
+
+  TargetTuple t1 = tuple;                                  // converting copy constructor
+  TargetTuple t2 = std::move(tuple);                       // converting move constructor
+  TargetTuple t3 = static_cast<LargeTuple const&&>(tuple); // converting const rvalue constructor
+  TargetTuple t4;                                          // default constructor
+  (void)t1; (void)t2; (void)t3; (void)t4;
+
+#if TEST_STD_VER >= 20
+  t3 = tuple;                                              // converting copy assignment
+  t2 = std::move(tuple);                                   // converting move assignment
+  swap(t1, t4);                                            // swap
+#endif
+  // t1 == tuple;                                          // comparison does not work yet (we blow the constexpr stack)
 }
 
 constexpr bool test() {
Index: libcxx/include/tuple
===================================================================
--- libcxx/include/tuple
+++ libcxx/include/tuple
@@ -883,13 +883,13 @@
     template <class... _Up, enable_if_t<
         _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
     _LIBCPP_HIDE_FROM_ABI constexpr
-        explicit(!(is_convertible_v<_Up&, _Tp> && ...))
+        explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value)
     tuple(tuple<_Up...>& __t) : __base_(__t) {}
 
     template <class _Alloc, class... _Up, enable_if_t<
         _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr>
     _LIBCPP_HIDE_FROM_ABI constexpr
-        explicit(!(is_convertible_v<_Up&, _Tp> && ...))
+        explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value)
     tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t) : __base_(allocator_arg_t(), __alloc, __t) {}
 #endif // _LIBCPP_STD_VER >= 23
 
@@ -947,13 +947,13 @@
     template <class... _Up, enable_if_t<
         _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
     _LIBCPP_HIDE_FROM_ABI constexpr
-        explicit(!(is_convertible_v<const _Up&&, _Tp> && ...))
+        explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value)
     tuple(const tuple<_Up...>&& __t) : __base_(std::move(__t)) {}
 
     template <class _Alloc, class... _Up, enable_if_t<
         _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr>
     _LIBCPP_HIDE_FROM_ABI constexpr
-        explicit(!(is_convertible_v<const _Up&&, _Tp> && ...))
+        explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value)
     tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t)
         : __base_(allocator_arg_t(), __alloc, std::move(__t)) {}
 #endif // _LIBCPP_STD_VER >= 23


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132509.557068.patch
Type: text/x-patch
Size: 3726 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230919/5404d7c2/attachment.bin>


More information about the libcxx-commits mailing list