[gcc r13-2158] libstdc++: Separate construct/convertibility tests for std::tuple

Patrick Palka ppalka@gcc.gnu.org
Tue Aug 23 17:46:38 GMT 2022


https://gcc.gnu.org/g:02f6b405f0e9dc7a8868fecef9a048b79c433125

commit r13-2158-g02f6b405f0e9dc7a8868fecef9a048b79c433125
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Aug 23 13:35:49 2022 -0400

    libstdc++: Separate construct/convertibility tests for std::tuple
    
    P2321R2 adds additional conditionally explicit constructors to std::tuple
    which we'll concisely implement in a subsequent patch using explicit(bool),
    like in our C++20 std::pair implementation.  This prerequisite patch
    adds member typedefs to _TupleConstraints for testing element-wise
    constructibility and convertibility separately; we'll use the first in
    the new constructors' constraints, and the second in their explicit
    specifier.
    
    In passing, this patch also redefines the existing member predicates
    __is_ex/implicitly_constructible in terms of these new members.  This
    seems to reduce compile time and memory usage by about 10% for large
    tuples when using the converting constructors that're constrained by
    _Explicit/_ImplicitCtor.
    
    libstdc++-v3/ChangeLog:
    
            * include/std/tuple (_TupleConstraints::__convertible): Define.
            (_TupleConstraints::__constructible): Define.
            (_TupleConstraints::__is_explicitly_constructible): Redefine this
            in terms of __convertible and __constructible.
            (_TupleConstraints::__is_implicitly_constructible): Likewise.

Diff:
---
 libstdc++-v3/include/std/tuple | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index 6d0060a191c..7f9c07248d4 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -553,14 +553,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<bool, typename... _Types>
     struct _TupleConstraints
     {
+      template<typename... _UTypes>
+	using __constructible = __and_<is_constructible<_Types, _UTypes>...>;
+
+      template<typename... _UTypes>
+	using __convertible = __and_<is_convertible<_UTypes, _Types>...>;
+
       // Constraint for a non-explicit constructor.
       // True iff each Ti in _Types... can be constructed from Ui in _UTypes...
       // and every Ui is implicitly convertible to Ti.
       template<typename... _UTypes>
 	static constexpr bool __is_implicitly_constructible()
 	{
-	  return __and_<is_constructible<_Types, _UTypes>...,
-			is_convertible<_UTypes, _Types>...
+	  return __and_<__constructible<_UTypes...>,
+			__convertible<_UTypes...>
 			>::value;
 	}
 
@@ -570,8 +576,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename... _UTypes>
 	static constexpr bool __is_explicitly_constructible()
 	{
-	  return __and_<is_constructible<_Types, _UTypes>...,
-			__not_<__and_<is_convertible<_UTypes, _Types>...>>
+	  return __and_<__constructible<_UTypes...>,
+			__not_<__convertible<_UTypes...>>
 			>::value;
 	}


More information about the Libstdc++-cvs mailing list