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

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 23 15:35:35 PDT 2022


ldionne created this revision.
Herald added a project: All.
ldionne requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

This reduces the number of instantiations and also avoid blowing up
past the fold-expression limit of Clang.

This is NOT a general statement that we should strive to stay within
Clang's (sometimes way too small) limits, however in this case the
change will reduce the number of template instantiations while at the
same time doing that, which is good.


Repository:
  rG LLVM Github Monorepo

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
@@ -17,9 +17,17 @@
 
 template <size_t... I>
 constexpr void CreateTuple(std::index_sequence<I...>) {
-  std::tuple<decltype(I)...> tuple(I...);
+  using LargeTuple = std::tuple<decltype(I)...>;
+  LargeTuple tuple(I...);
   assert(std::get<0>(tuple) == 0);
   assert(std::get<sizeof...(I)-1>(tuple) == sizeof...(I)-1);
+  LargeTuple t2 = tuple;            // copy constructor
+  LargeTuple t3 = std::move(tuple); // move constructor
+  LargeTuple t4;                    // default constructor
+  t3 = t2;                          // copy assignment
+  t4 = std::move(t2);               // move assignment
+  swap(t3, t4);                     // swap
+  // equality (t3 == t4) does not work
 }
 
 constexpr bool test() {
Index: libcxx/include/tuple
===================================================================
--- libcxx/include/tuple
+++ libcxx/include/tuple
@@ -844,13 +844,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 > 20
 
@@ -908,13 +908,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 > 20


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132509.454990.patch
Type: text/x-patch
Size: 2862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220823/12950aff/attachment.bin>


More information about the libcxx-commits mailing list