]> git.ipfire.org Git - thirdparty/gcc.git/commit
Refactor SFINAE constraints on std::tuple constructors
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 6 Jun 2019 12:13:36 +0000 (12:13 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 6 Jun 2019 12:13:36 +0000 (12:13 +0000)
commit42c1dacdb129b5338ee4168d66fec9e57b0aed58
treea04a6cf1307706d62e1a1154cd84c49ebcba208c
parent138c5492d823b9a488758b28db070f80156fc1ed
Refactor SFINAE constraints on std::tuple constructors

Replace the _TC class template with the better-named _TupleConstraints
one, which provides a different set of member functions. The new members
do not distinguish construction from lvalues and rvalues, but expects
the caller to do that by providing different template arguments. Within
the std::tuple primary template and std::tuple<T1, T2> partial
specialization the _TupleConstraints members are used via new alias
templates like _ImplicitCtor and _ExplicitCtor which makes the
constructor constraints less verbose and repetitive. For example, where
we previously had:

     template<typename... _UElements, typename
             enable_if<
                _TMC<_UElements...>::template
                   _MoveConstructibleTuple<_UElements...>()
                 && _TMC<_UElements...>::template
                   _ImplicitlyMoveConvertibleTuple<_UElements...>()
                 && (sizeof...(_Elements) >= 1),
       bool>::type=true>
       constexpr tuple(_UElements&&... __elements)

We now have:

     template<typename... _UElements,
             bool _Valid = __valid_args<_UElements...>(),
             _ImplicitCtor<_Valid, _UElements...> = true>
      constexpr
      tuple(_UElements&&... __elements)

There are two semantic changes as a result of the refactoring:

- The allocator-extended default constructor is now constrained.
- The rewritten constraints fix PR 90700.

* include/std/tuple (_TC): Replace with _TupleConstraints.
(_TupleConstraints): New helper for SFINAE constraints, with more
expressive member functions to reduce duplication when used.
(tuple::_TC2, tuple::_TMC, tuple::_TNTC): Remove.
(tuple::_TCC): Replace dummy type parameter with bool non-type
parameter that can be used to check the pack size.
(tuple::_ImplicitDefaultCtor, tuple::_ExplicitDefaultCtor)
(tuple::_ImplicitCtor, tuple::_ExplicitCtor): New alias templates for
checking constraints in constructors.
(tuple::__valid_args, tuple::_UseOtherCtor, tuple::__use_other_ctor):
New SFINAE helpers.
(tuple::tuple): Use new helpers to reduce repitition in constraints.
(tuple::tuple(allocator_arg_t, const Alloc&)): Constrain.
(tuple<T1, T2>::_TCC, tuple<T1, T2>::_ImplicitDefaultCtor)
(tuple<T1, T2>::_ExplicitDefaultCtor, tuple<T1, T2>::_ImplicitCtor)
(tuple<T1, T2>::_ExplicitCtor): New alias templates for checking
constraints in constructors.
(tuple::__is_alloc_arg()): New SFINAE helpers.
(tuple<T1, T2>::tuple): Use new helpers to reduce repitition in
constraints.
(tuple<T1, T2>::tuple(allocator_arg_t, const Alloc&)): Constrain.
* testsuite/20_util/tuple/cons/90700.cc: New test.
* testsuite/20_util/tuple/cons/allocators.cc: Add default constructor
to meet new constraint on allocator-extended default constructor.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@271998 138bc75d-0d04-0410-961f-82ee72b054a4
libstdc++-v3/ChangeLog
libstdc++-v3/include/std/tuple
libstdc++-v3/testsuite/20_util/tuple/cons/90700.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/tuple/cons/allocators.cc