Commit d355635e by Jonathan Wakely Committed by Jonathan Wakely

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.

From-SVN: r271998
parent ec573765
2019-06-06 Jonathan Wakely <jwakely@redhat.com>
* 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.
2019-06-03 Jonathan Wakely <jwakely@redhat.com>
* include/bits/stl_map.h (map): Disable static assert for C++98 mode.
......
......@@ -433,90 +433,59 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Concept utility functions, reused in conditionally-explicit
// constructors.
template<bool, typename... _Elements>
struct _TC
{
template<typename... _UElements>
static constexpr bool _ConstructibleTuple()
{
return __and_<is_constructible<_Elements, const _UElements&>...>::value;
}
template<typename... _UElements>
static constexpr bool _ImplicitlyConvertibleTuple()
{
return __and_<is_convertible<const _UElements&, _Elements>...>::value;
}
template<typename... _UElements>
static constexpr bool _MoveConstructibleTuple()
{
return __and_<is_constructible<_Elements, _UElements&&>...>::value;
}
template<typename... _UElements>
static constexpr bool _ImplicitlyMoveConvertibleTuple()
{
return __and_<is_convertible<_UElements&&, _Elements>...>::value;
}
template<typename _SrcTuple>
static constexpr bool _NonNestedTuple()
{
return __and_<__not_<is_same<tuple<_Elements...>,
__remove_cvref_t<_SrcTuple>>>,
__not_<is_convertible<_SrcTuple, _Elements...>>,
__not_<is_constructible<_Elements..., _SrcTuple>>
>::value;
}
template<typename... _UElements>
static constexpr bool _NotSameTuple()
{
return __not_<is_same<tuple<_Elements...>,
__remove_cvref_t<_UElements>...>>::value;
}
};
template<typename... _Elements>
struct _TC<false, _Elements...>
{
template<typename... _UElements>
static constexpr bool _ConstructibleTuple()
template<bool, typename... _Types>
struct _TupleConstraints
{
return false;
}
// 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>...
>::value;
}
template<typename... _UElements>
static constexpr bool _ImplicitlyConvertibleTuple()
{
return false;
}
// Constraint for a non-explicit constructor.
// True iff each Ti in _Types... can be constructed from Ui in _UTypes...
// but not every Ui is implicitly convertible to Ti.
template<typename... _UTypes>
static constexpr bool __is_explicitly_constructible()
{
return __and_<is_constructible<_Types, _UTypes>...,
__not_<__and_<is_convertible<_UTypes, _Types>...>>
>::value;
}
template<typename... _UElements>
static constexpr bool _MoveConstructibleTuple()
{
return false;
}
static constexpr bool __is_implicitly_default_constructible()
{
return __and_<std::__is_implicitly_default_constructible<_Types>...
>::value;
}
template<typename... _UElements>
static constexpr bool _ImplicitlyMoveConvertibleTuple()
{
return false;
}
static constexpr bool __is_explicitly_default_constructible()
{
return __and_<is_default_constructible<_Types>...,
__not_<__and_<
std::__is_implicitly_default_constructible<_Types>...>
>>::value;
}
};
template<typename... _UElements>
static constexpr bool _NonNestedTuple()
// Partial specialization used when a required precondition isn't met,
// e.g. when sizeof...(_Types) != sizeof...(_UTypes).
template<typename... _Types>
struct _TupleConstraints<false, _Types...>
{
return true;
}
template<typename... _UTypes>
static constexpr bool __is_implicitly_constructible()
{ return false; }
template<typename... _UElements>
static constexpr bool _NotSameTuple()
{
return true;
}
};
template<typename... _UTypes>
static constexpr bool __is_explicitly_constructible()
{ return false; }
};
/// Primary class template, tuple
template<typename... _Elements>
......@@ -524,21 +493,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
typedef _Tuple_impl<0, _Elements...> _Inherited;
// Used for constraining the default constructor so
// that it becomes dependent on the constraints.
template<typename _Dummy>
struct _TC2
{
static constexpr bool _DefaultConstructibleTuple()
{
return __and_<is_default_constructible<_Elements>...>::value;
}
static constexpr bool _ImplicitlyDefaultConstructibleTuple()
{
return __and_<__is_implicitly_default_constructible<_Elements>...>
::value;
}
};
template<bool _Cond>
using _TCC = _TupleConstraints<_Cond, _Elements...>;
// Constraint for non-explicit default constructor
template<bool _Dummy>
using _ImplicitDefaultCtor = __enable_if_t<
_TCC<_Dummy>::__is_implicitly_default_constructible(),
bool>;
// Constraint for explicit default constructor
template<bool _Dummy>
using _ExplicitDefaultCtor = __enable_if_t<
_TCC<_Dummy>::__is_explicitly_default_constructible(),
bool>;
// Constraint for non-explicit constructors
template<bool _Cond, typename... _Args>
using _ImplicitCtor = __enable_if_t<
_TCC<_Cond>::template __is_implicitly_constructible<_Args...>(),
bool>;
// Constraint for non-explicit constructors
template<bool _Cond, typename... _Args>
using _ExplicitCtor = __enable_if_t<
_TCC<_Cond>::template __is_explicitly_constructible<_Args...>(),
bool>;
template<typename... _UElements>
static constexpr
......@@ -546,12 +526,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__assignable()
{ return __and_<is_assignable<_Elements&, _UElements>...>::value; }
// Condition for noexcept-specifier of an assignment operator.
template<typename... _UElements>
static constexpr bool __nothrow_assignable()
{
return
__and_<is_nothrow_assignable<_Elements&, _UElements>...>::value;
}
// Condition for noexcept-specifier of a constructor.
template<typename... _UElements>
static constexpr bool __nothrow_constructible()
{
......@@ -559,205 +542,176 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__and_<is_nothrow_constructible<_Elements, _UElements>...>::value;
}
public:
template<typename _Dummy = void,
typename enable_if<_TC2<_Dummy>::
_ImplicitlyDefaultConstructibleTuple(),
bool>::type = true>
constexpr tuple()
noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value)
: _Inherited() { }
// Constraint for tuple(_UTypes&&...) where sizeof...(_UTypes) == 1.
template<typename _Up>
static constexpr bool __valid_args()
{
return sizeof...(_Elements) == 1
&& !is_same<tuple, __remove_cvref_t<_Up>>::value;
}
template<typename _Dummy = void,
typename enable_if<_TC2<_Dummy>::
_DefaultConstructibleTuple()
&&
!_TC2<_Dummy>::
_ImplicitlyDefaultConstructibleTuple(),
bool>::type = false>
explicit constexpr tuple()
noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value)
: _Inherited() { }
// Shortcut for the cases where constructors taking _Elements...
// need to be constrained.
template<typename _Dummy> using _TCC =
_TC<is_same<_Dummy, void>::value,
_Elements...>;
// Constraint for tuple(_UTypes&&...) where sizeof...(_UTypes) > 1.
template<typename, typename, typename... _Tail>
static constexpr bool __valid_args()
{ return (sizeof...(_Tail) + 2) == sizeof...(_Elements); }
/* Constraint for constructors with a tuple<UTypes...> parameter ensures
* that the constructor is only viable when it would not interfere with
* tuple(UTypes&&...) or tuple(const tuple&) or tuple(tuple&&).
* Such constructors are only viable if:
* either sizeof...(Types) != 1,
* or (when Types... expands to T and UTypes... expands to U)
* is_convertible_v<TUPLE, T>, is_constructible_v<T, TUPLE>,
* and is_same_v<T, U> are all false.
*/
template<typename _Tuple, typename = tuple,
typename = __remove_cvref_t<_Tuple>>
struct _UseOtherCtor
: false_type
{ };
// If TUPLE is convertible to the single element in *this,
// then TUPLE should match tuple(UTypes&&...) instead.
template<typename _Tuple, typename _Tp, typename _Up>
struct _UseOtherCtor<_Tuple, tuple<_Tp>, tuple<_Up>>
: __or_<is_convertible<_Tuple, _Tp>, is_constructible<_Tp, _Tuple>>
{ };
// If TUPLE and *this each have a single element of the same type,
// then TUPLE should match a copy/move constructor instead.
template<typename _Tuple, typename _Tp>
struct _UseOtherCtor<_Tuple, tuple<_Tp>, tuple<_Tp>>
: true_type
{ };
// Return true iff sizeof...(Types) == 1 && tuple_size_v<TUPLE> == 1
// and the single element in Types can be initialized from TUPLE,
// or is the same type as tuple_element_t<0, TUPLE>.
template<typename _Tuple>
static constexpr bool __use_other_ctor()
{ return _UseOtherCtor<_Tuple>::value; }
public:
template<typename _Dummy = void,
typename enable_if<
_TCC<_Dummy>::template
_ConstructibleTuple<_Elements...>()
&& _TCC<_Dummy>::template
_ImplicitlyConvertibleTuple<_Elements...>()
&& (sizeof...(_Elements) >= 1),
bool>::type=true>
constexpr tuple(const _Elements&... __elements)
noexcept(__nothrow_constructible<const _Elements&...>())
: _Inherited(__elements...) { }
_ImplicitDefaultCtor<is_void<_Dummy>::value> = true>
constexpr
tuple()
noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value)
: _Inherited() { }
template<typename _Dummy = void,
typename enable_if<
_TCC<_Dummy>::template
_ConstructibleTuple<_Elements...>()
&& !_TCC<_Dummy>::template
_ImplicitlyConvertibleTuple<_Elements...>()
&& (sizeof...(_Elements) >= 1),
bool>::type=false>
explicit constexpr tuple(const _Elements&... __elements)
noexcept(__nothrow_constructible<const _Elements&...>())
: _Inherited(__elements...) { }
// Shortcut for the cases where constructors taking _UElements...
// need to be constrained.
template<typename... _UElements> using _TMC =
_TC<(sizeof...(_Elements) == sizeof...(_UElements))
&& (_TC<(sizeof...(_UElements)==1), _Elements...>::
template _NotSameTuple<_UElements...>()),
_Elements...>;
// Shortcut for the cases where constructors taking tuple<_UElements...>
// need to be constrained.
template<typename... _UElements> using _TMCT =
_TC<(sizeof...(_Elements) == sizeof...(_UElements))
&& !is_same<tuple<_Elements...>,
tuple<_UElements...>>::value,
_Elements...>;
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)
noexcept(__nothrow_constructible<_UElements...>())
: _Inherited(std::forward<_UElements>(__elements)...) { }
template<typename... _UElements, typename
enable_if<
_TMC<_UElements...>::template
_MoveConstructibleTuple<_UElements...>()
&& !_TMC<_UElements...>::template
_ImplicitlyMoveConvertibleTuple<_UElements...>()
&& (sizeof...(_Elements) >= 1),
bool>::type=false>
explicit constexpr tuple(_UElements&&... __elements)
noexcept(__nothrow_constructible<_UElements...>())
_ExplicitDefaultCtor<is_void<_Dummy>::value> = false>
explicit constexpr
tuple()
noexcept(__and_<is_nothrow_default_constructible<_Elements>...>::value)
: _Inherited() { }
template<bool _NotEmpty = (sizeof...(_Elements) >= 1),
_ImplicitCtor<_NotEmpty, const _Elements&...> = true>
constexpr
tuple(const _Elements&... __elements)
noexcept(__nothrow_constructible<const _Elements&...>())
: _Inherited(__elements...) { }
template<bool _NotEmpty = (sizeof...(_Elements) >= 1),
_ExplicitCtor<_NotEmpty, const _Elements&...> = false>
explicit constexpr
tuple(const _Elements&... __elements)
noexcept(__nothrow_constructible<const _Elements&...>())
: _Inherited(__elements...) { }
template<typename... _UElements,
bool _Valid = __valid_args<_UElements...>(),
_ImplicitCtor<_Valid, _UElements...> = true>
constexpr
tuple(_UElements&&... __elements)
noexcept(__nothrow_constructible<_UElements...>())
: _Inherited(std::forward<_UElements>(__elements)...) { }
template<typename... _UElements,
bool _Valid = __valid_args<_UElements...>(),
_ExplicitCtor<_Valid, _UElements...> = false>
explicit constexpr
tuple(_UElements&&... __elements)
noexcept(__nothrow_constructible<_UElements...>())
: _Inherited(std::forward<_UElements>(__elements)...) { }
constexpr tuple(const tuple&) = default;
constexpr tuple(tuple&&) = default;
// Shortcut for the cases where constructors taking tuples
// must avoid creating temporaries.
template<typename _Dummy> using _TNTC =
_TC<is_same<_Dummy, void>::value && sizeof...(_Elements) == 1,
_Elements...>;
template<typename... _UElements, typename _Dummy = void, typename
enable_if<_TMCT<_UElements...>::template
_ConstructibleTuple<_UElements...>()
&& _TMCT<_UElements...>::template
_ImplicitlyConvertibleTuple<_UElements...>()
&& _TNTC<_Dummy>::template
_NonNestedTuple<const tuple<_UElements...>&>(),
bool>::type=true>
constexpr tuple(const tuple<_UElements...>& __in)
noexcept(__nothrow_constructible<const _UElements&...>())
: _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
{ }
template<typename... _UElements, typename _Dummy = void, typename
enable_if<_TMCT<_UElements...>::template
_ConstructibleTuple<_UElements...>()
&& !_TMCT<_UElements...>::template
_ImplicitlyConvertibleTuple<_UElements...>()
&& _TNTC<_Dummy>::template
_NonNestedTuple<const tuple<_UElements...>&>(),
bool>::type=false>
explicit constexpr tuple(const tuple<_UElements...>& __in)
noexcept(__nothrow_constructible<const _UElements&...>())
: _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
{ }
template<typename... _UElements, typename _Dummy = void, typename
enable_if<_TMCT<_UElements...>::template
_MoveConstructibleTuple<_UElements...>()
&& _TMCT<_UElements...>::template
_ImplicitlyMoveConvertibleTuple<_UElements...>()
&& _TNTC<_Dummy>::template
_NonNestedTuple<tuple<_UElements...>&&>(),
bool>::type=true>
constexpr tuple(tuple<_UElements...>&& __in)
noexcept(__nothrow_constructible<_UElements...>())
: _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
template<typename... _UElements, typename _Dummy = void, typename
enable_if<_TMCT<_UElements...>::template
_MoveConstructibleTuple<_UElements...>()
&& !_TMCT<_UElements...>::template
_ImplicitlyMoveConvertibleTuple<_UElements...>()
&& _TNTC<_Dummy>::template
_NonNestedTuple<tuple<_UElements...>&&>(),
bool>::type=false>
explicit constexpr tuple(tuple<_UElements...>&& __in)
noexcept(__nothrow_constructible<_UElements...>())
: _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
template<typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<const tuple<_UElements...>&>(),
_ImplicitCtor<_Valid, const _UElements&...> = true>
constexpr
tuple(const tuple<_UElements...>& __in)
noexcept(__nothrow_constructible<const _UElements&...>())
: _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
{ }
template<typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<const tuple<_UElements...>&>(),
_ExplicitCtor<_Valid, const _UElements&...> = false>
explicit constexpr
tuple(const tuple<_UElements...>& __in)
noexcept(__nothrow_constructible<const _UElements&...>())
: _Inherited(static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
{ }
template<typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<tuple<_UElements...>&&>(),
_ImplicitCtor<_Valid, _UElements...> = true>
constexpr
tuple(tuple<_UElements...>&& __in)
noexcept(__nothrow_constructible<_UElements...>())
: _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
template<typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<tuple<_UElements...>&&>(),
_ExplicitCtor<_Valid, _UElements...> = false>
explicit constexpr
tuple(tuple<_UElements...>&& __in)
noexcept(__nothrow_constructible<_UElements...>())
: _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
// Allocator-extended constructors.
template<typename _Alloc>
template<typename _Alloc,
_ImplicitDefaultCtor<is_object<_Alloc>::value> = true>
tuple(allocator_arg_t __tag, const _Alloc& __a)
: _Inherited(__tag, __a) { }
template<typename _Alloc, typename _Dummy = void,
typename enable_if<
_TCC<_Dummy>::template
_ConstructibleTuple<_Elements...>()
&& _TCC<_Dummy>::template
_ImplicitlyConvertibleTuple<_Elements...>(),
bool>::type=true>
template<typename _Alloc, bool _NotEmpty = (sizeof...(_Elements) >= 1),
_ImplicitCtor<_NotEmpty, const _Elements&...> = true>
tuple(allocator_arg_t __tag, const _Alloc& __a,
const _Elements&... __elements)
: _Inherited(__tag, __a, __elements...) { }
template<typename _Alloc, typename _Dummy = void,
typename enable_if<
_TCC<_Dummy>::template
_ConstructibleTuple<_Elements...>()
&& !_TCC<_Dummy>::template
_ImplicitlyConvertibleTuple<_Elements...>(),
bool>::type=false>
explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
const _Elements&... __elements)
template<typename _Alloc, bool _NotEmpty = (sizeof...(_Elements) >= 1),
_ExplicitCtor<_NotEmpty, const _Elements&...> = false>
explicit
tuple(allocator_arg_t __tag, const _Alloc& __a,
const _Elements&... __elements)
: _Inherited(__tag, __a, __elements...) { }
template<typename _Alloc, typename... _UElements, typename
enable_if<_TMC<_UElements...>::template
_MoveConstructibleTuple<_UElements...>()
&& _TMC<_UElements...>::template
_ImplicitlyMoveConvertibleTuple<_UElements...>(),
bool>::type=true>
template<typename _Alloc, typename... _UElements,
bool _Valid = __valid_args<_UElements...>(),
_ImplicitCtor<_Valid, _UElements...> = true>
tuple(allocator_arg_t __tag, const _Alloc& __a,
_UElements&&... __elements)
: _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
{ }
template<typename _Alloc, typename... _UElements, typename
enable_if<_TMC<_UElements...>::template
_MoveConstructibleTuple<_UElements...>()
&& !_TMC<_UElements...>::template
_ImplicitlyMoveConvertibleTuple<_UElements...>(),
bool>::type=false>
explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
{ }
template<typename _Alloc, typename... _UElements,
bool _Valid = __valid_args<_UElements...>(),
_ExplicitCtor<_Valid, _UElements...> = false>
explicit
tuple(allocator_arg_t __tag, const _Alloc& __a,
_UElements&&... __elements)
: _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
{ }
{ }
template<typename _Alloc>
tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
......@@ -767,61 +721,43 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
: _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
template<typename _Alloc, typename _Dummy = void,
typename... _UElements, typename
enable_if<_TMCT<_UElements...>::template
_ConstructibleTuple<_UElements...>()
&& _TMCT<_UElements...>::template
_ImplicitlyConvertibleTuple<_UElements...>()
&& _TNTC<_Dummy>::template
_NonNestedTuple<tuple<_UElements...>&&>(),
bool>::type=true>
template<typename _Alloc, typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<const tuple<_UElements...>&>(),
_ImplicitCtor<_Valid, const _UElements&...> = true>
tuple(allocator_arg_t __tag, const _Alloc& __a,
const tuple<_UElements...>& __in)
: _Inherited(__tag, __a,
static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
{ }
template<typename _Alloc, typename _Dummy = void,
typename... _UElements, typename
enable_if<_TMCT<_UElements...>::template
_ConstructibleTuple<_UElements...>()
&& !_TMCT<_UElements...>::template
_ImplicitlyConvertibleTuple<_UElements...>()
&& _TNTC<_Dummy>::template
_NonNestedTuple<tuple<_UElements...>&&>(),
bool>::type=false>
explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
template<typename _Alloc, typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<const tuple<_UElements...>&>(),
_ExplicitCtor<_Valid, const _UElements&...> = false>
explicit
tuple(allocator_arg_t __tag, const _Alloc& __a,
const tuple<_UElements...>& __in)
: _Inherited(__tag, __a,
static_cast<const _Tuple_impl<0, _UElements...>&>(__in))
{ }
template<typename _Alloc, typename _Dummy = void,
typename... _UElements, typename
enable_if<_TMCT<_UElements...>::template
_MoveConstructibleTuple<_UElements...>()
&& _TMCT<_UElements...>::template
_ImplicitlyMoveConvertibleTuple<_UElements...>()
&& _TNTC<_Dummy>::template
_NonNestedTuple<tuple<_UElements...>&&>(),
bool>::type=true>
template<typename _Alloc, typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<tuple<_UElements...>&&>(),
_ImplicitCtor<_Valid, _UElements...> = true>
tuple(allocator_arg_t __tag, const _Alloc& __a,
tuple<_UElements...>&& __in)
: _Inherited(__tag, __a,
static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
{ }
template<typename _Alloc, typename _Dummy = void,
typename... _UElements, typename
enable_if<_TMCT<_UElements...>::template
_MoveConstructibleTuple<_UElements...>()
&& !_TMCT<_UElements...>::template
_ImplicitlyMoveConvertibleTuple<_UElements...>()
&& _TNTC<_Dummy>::template
_NonNestedTuple<tuple<_UElements...>&&>(),
bool>::type=false>
explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
template<typename _Alloc, typename... _UElements,
bool _Valid = (sizeof...(_Elements) == sizeof...(_UElements))
&& !__use_other_ctor<tuple<_UElements...>&&>(),
_ExplicitCtor<_Valid, _UElements...> = false>
explicit
tuple(allocator_arg_t __tag, const _Alloc& __a,
tuple<_UElements...>&& __in)
: _Inherited(__tag, __a,
static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
......@@ -910,6 +846,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
typedef _Tuple_impl<0, _T1, _T2> _Inherited;
// Constraint for non-explicit default constructor
template<bool _Dummy, typename _U1, typename _U2>
using _ImplicitDefaultCtor = __enable_if_t<
_TupleConstraints<_Dummy, _U1, _U2>::
__is_implicitly_default_constructible(),
bool>;
// Constraint for explicit default constructor
template<bool _Dummy, typename _U1, typename _U2>
using _ExplicitDefaultCtor = __enable_if_t<
_TupleConstraints<_Dummy, _U1, _U2>::
__is_explicitly_default_constructible(),
bool>;
template<bool _Dummy>
using _TCC = _TupleConstraints<_Dummy, _T1, _T2>;
// Constraint for non-explicit constructors
template<bool _Cond, typename _U1, typename _U2>
using _ImplicitCtor = __enable_if_t<
_TCC<_Cond>::template __is_implicitly_constructible<_U1, _U2>(),
bool>;
// Constraint for non-explicit constructors
template<bool _Cond, typename _U1, typename _U2>
using _ExplicitCtor = __enable_if_t<
_TCC<_Cond>::template __is_explicitly_constructible<_U1, _U2>(),
bool>;
template<typename _U1, typename _U2>
static constexpr bool __assignable()
{
......@@ -937,215 +902,146 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
is_nothrow_default_constructible<_T2>>::value;
}
template<typename _U1>
static constexpr bool __is_alloc_arg()
{ return is_same<__remove_cvref_t<_U1>, allocator_arg_t>::value; }
public:
template <typename _U1 = _T1,
typename _U2 = _T2,
typename enable_if<__and_<
__is_implicitly_default_constructible<_U1>,
__is_implicitly_default_constructible<_U2>>
::value, bool>::type = true>
constexpr tuple()
template<bool _Dummy = true,
_ImplicitDefaultCtor<_Dummy, _T1, _T2> = true>
constexpr
tuple()
noexcept(__nothrow_default_constructible())
: _Inherited() { }
template <typename _U1 = _T1,
typename _U2 = _T2,
typename enable_if<
__and_<
is_default_constructible<_U1>,
is_default_constructible<_U2>,
__not_<
__and_<__is_implicitly_default_constructible<_U1>,
__is_implicitly_default_constructible<_U2>>>>
::value, bool>::type = false>
explicit constexpr tuple()
template<bool _Dummy = true,
_ExplicitDefaultCtor<_Dummy, _T1, _T2> = false>
explicit constexpr
tuple()
noexcept(__nothrow_default_constructible())
: _Inherited() { }
// Shortcut for the cases where constructors taking _T1, _T2
// need to be constrained.
template<typename _Dummy> using _TCC =
_TC<is_same<_Dummy, void>::value, _T1, _T2>;
template<typename _Dummy = void, typename
enable_if<_TCC<_Dummy>::template
_ConstructibleTuple<_T1, _T2>()
&& _TCC<_Dummy>::template
_ImplicitlyConvertibleTuple<_T1, _T2>(),
bool>::type = true>
constexpr tuple(const _T1& __a1, const _T2& __a2)
noexcept(__nothrow_constructible<const _T1&, const _T2&>())
: _Inherited(__a1, __a2) { }
template<typename _Dummy = void, typename
enable_if<_TCC<_Dummy>::template
_ConstructibleTuple<_T1, _T2>()
&& !_TCC<_Dummy>::template
_ImplicitlyConvertibleTuple<_T1, _T2>(),
bool>::type = false>
explicit constexpr tuple(const _T1& __a1, const _T2& __a2)
noexcept(__nothrow_constructible<const _T1&, const _T2&>())
: _Inherited(__a1, __a2) { }
// Shortcut for the cases where constructors taking _U1, _U2
// need to be constrained.
using _TMC = _TC<true, _T1, _T2>;
template<typename _U1, typename _U2, typename
enable_if<_TMC::template
_MoveConstructibleTuple<_U1, _U2>()
&& _TMC::template
_ImplicitlyMoveConvertibleTuple<_U1, _U2>()
&& !is_same<__remove_cvref_t<_U1>, allocator_arg_t>::value,
bool>::type = true>
constexpr tuple(_U1&& __a1, _U2&& __a2)
noexcept(__nothrow_constructible<_U1, _U2>())
template<bool _Dummy = true,
_ImplicitCtor<_Dummy, const _T1&, const _T2&> = true>
constexpr
tuple(const _T1& __a1, const _T2& __a2)
noexcept(__nothrow_constructible<const _T1&, const _T2&>())
: _Inherited(__a1, __a2) { }
template<bool _Dummy = true,
_ExplicitCtor<_Dummy, const _T1&, const _T2&> = false>
explicit constexpr
tuple(const _T1& __a1, const _T2& __a2)
noexcept(__nothrow_constructible<const _T1&, const _T2&>())
: _Inherited(__a1, __a2) { }
template<typename _U1, typename _U2,
_ImplicitCtor<!__is_alloc_arg<_U1>(), _U1, _U2> = true>
constexpr
tuple(_U1&& __a1, _U2&& __a2)
noexcept(__nothrow_constructible<_U1, _U2>())
: _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
template<typename _U1, typename _U2, typename
enable_if<_TMC::template
_MoveConstructibleTuple<_U1, _U2>()
&& !_TMC::template
_ImplicitlyMoveConvertibleTuple<_U1, _U2>()
&& !is_same<__remove_cvref_t<_U1>, allocator_arg_t>::value,
bool>::type = false>
explicit constexpr tuple(_U1&& __a1, _U2&& __a2)
noexcept(__nothrow_constructible<_U1, _U2>())
template<typename _U1, typename _U2,
_ExplicitCtor<!__is_alloc_arg<_U1>(), _U1, _U2> = false>
explicit constexpr
tuple(_U1&& __a1, _U2&& __a2)
noexcept(__nothrow_constructible<_U1, _U2>())
: _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
constexpr tuple(const tuple&) = default;
constexpr tuple(tuple&&) = default;
template<typename _U1, typename _U2, typename
enable_if<_TMC::template
_ConstructibleTuple<_U1, _U2>()
&& _TMC::template
_ImplicitlyConvertibleTuple<_U1, _U2>(),
bool>::type = true>
constexpr tuple(const tuple<_U1, _U2>& __in)
noexcept(__nothrow_constructible<const _U1&, const _U2&>())
template<typename _U1, typename _U2,
_ImplicitCtor<true, const _U1&, const _U2&> = true>
constexpr
tuple(const tuple<_U1, _U2>& __in)
noexcept(__nothrow_constructible<const _U1&, const _U2&>())
: _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
template<typename _U1, typename _U2, typename
enable_if<_TMC::template
_ConstructibleTuple<_U1, _U2>()
&& !_TMC::template
_ImplicitlyConvertibleTuple<_U1, _U2>(),
bool>::type = false>
explicit constexpr tuple(const tuple<_U1, _U2>& __in)
noexcept(__nothrow_constructible<const _U1&, const _U2&>())
template<typename _U1, typename _U2,
_ExplicitCtor<true, const _U1&, const _U2&> = false>
explicit constexpr
tuple(const tuple<_U1, _U2>& __in)
noexcept(__nothrow_constructible<const _U1&, const _U2&>())
: _Inherited(static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in)) { }
template<typename _U1, typename _U2, typename
enable_if<_TMC::template
_MoveConstructibleTuple<_U1, _U2>()
&& _TMC::template
_ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
bool>::type = true>
constexpr tuple(tuple<_U1, _U2>&& __in)
noexcept(__nothrow_constructible<_U1, _U2>())
template<typename _U1, typename _U2,
_ImplicitCtor<true, _U1, _U2> = true>
constexpr
tuple(tuple<_U1, _U2>&& __in)
noexcept(__nothrow_constructible<_U1, _U2>())
: _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
template<typename _U1, typename _U2, typename
enable_if<_TMC::template
_MoveConstructibleTuple<_U1, _U2>()
&& !_TMC::template
_ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
bool>::type = false>
explicit constexpr tuple(tuple<_U1, _U2>&& __in)
noexcept(__nothrow_constructible<_U1, _U2>())
template<typename _U1, typename _U2,
_ExplicitCtor<true, _U1, _U2> = false>
explicit constexpr
tuple(tuple<_U1, _U2>&& __in)
noexcept(__nothrow_constructible<_U1, _U2>())
: _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
template<typename _U1, typename _U2, typename
enable_if<_TMC::template
_ConstructibleTuple<_U1, _U2>()
&& _TMC::template
_ImplicitlyConvertibleTuple<_U1, _U2>(),
bool>::type = true>
constexpr tuple(const pair<_U1, _U2>& __in)
noexcept(__nothrow_constructible<const _U1&, const _U2&>())
template<typename _U1, typename _U2,
_ImplicitCtor<true, const _U1&, const _U2&> = true>
constexpr
tuple(const pair<_U1, _U2>& __in)
noexcept(__nothrow_constructible<const _U1&, const _U2&>())
: _Inherited(__in.first, __in.second) { }
template<typename _U1, typename _U2, typename
enable_if<_TMC::template
_ConstructibleTuple<_U1, _U2>()
&& !_TMC::template
_ImplicitlyConvertibleTuple<_U1, _U2>(),
bool>::type = false>
explicit constexpr tuple(const pair<_U1, _U2>& __in)
noexcept(__nothrow_constructible<const _U1&, const _U2&>())
template<typename _U1, typename _U2,
_ExplicitCtor<true, const _U1&, const _U2&> = false>
explicit constexpr
tuple(const pair<_U1, _U2>& __in)
noexcept(__nothrow_constructible<const _U1&, const _U2&>())
: _Inherited(__in.first, __in.second) { }
template<typename _U1, typename _U2, typename
enable_if<_TMC::template
_MoveConstructibleTuple<_U1, _U2>()
&& _TMC::template
_ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
bool>::type = true>
constexpr tuple(pair<_U1, _U2>&& __in)
noexcept(__nothrow_constructible<_U1, _U2>())
template<typename _U1, typename _U2,
_ImplicitCtor<true, _U1, _U2> = true>
constexpr
tuple(pair<_U1, _U2>&& __in)
noexcept(__nothrow_constructible<_U1, _U2>())
: _Inherited(std::forward<_U1>(__in.first),
std::forward<_U2>(__in.second)) { }
template<typename _U1, typename _U2, typename
enable_if<_TMC::template
_MoveConstructibleTuple<_U1, _U2>()
&& !_TMC::template
_ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
bool>::type = false>
explicit constexpr tuple(pair<_U1, _U2>&& __in)
noexcept(__nothrow_constructible<_U1, _U2>())
template<typename _U1, typename _U2,
_ExplicitCtor<true, _U1, _U2> = false>
explicit constexpr
tuple(pair<_U1, _U2>&& __in)
noexcept(__nothrow_constructible<_U1, _U2>())
: _Inherited(std::forward<_U1>(__in.first),
std::forward<_U2>(__in.second)) { }
// Allocator-extended constructors.
template<typename _Alloc>
template<typename _Alloc,
_ImplicitDefaultCtor<is_object<_Alloc>::value, _T1, _T2> = true>
tuple(allocator_arg_t __tag, const _Alloc& __a)
: _Inherited(__tag, __a) { }
template<typename _Alloc, typename _Dummy = void,
typename enable_if<
_TCC<_Dummy>::template
_ConstructibleTuple<_T1, _T2>()
&& _TCC<_Dummy>::template
_ImplicitlyConvertibleTuple<_T1, _T2>(),
bool>::type=true>
template<typename _Alloc, bool _Dummy = true,
_ImplicitCtor<_Dummy, const _T1&, const _T2&> = true>
tuple(allocator_arg_t __tag, const _Alloc& __a,
const _T1& __a1, const _T2& __a2)
: _Inherited(__tag, __a, __a1, __a2) { }
template<typename _Alloc, typename _Dummy = void,
typename enable_if<
_TCC<_Dummy>::template
_ConstructibleTuple<_T1, _T2>()
&& !_TCC<_Dummy>::template
_ImplicitlyConvertibleTuple<_T1, _T2>(),
bool>::type=false>
explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
template<typename _Alloc, bool _Dummy = true,
_ExplicitCtor<_Dummy, const _T1&, const _T2&> = false>
explicit
tuple(allocator_arg_t __tag, const _Alloc& __a,
const _T1& __a1, const _T2& __a2)
: _Inherited(__tag, __a, __a1, __a2) { }
template<typename _Alloc, typename _U1, typename _U2, typename
enable_if<_TMC::template
_MoveConstructibleTuple<_U1, _U2>()
&& _TMC::template
_ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
bool>::type = true>
template<typename _Alloc, typename _U1, typename _U2,
_ImplicitCtor<true, _U1, _U2> = true>
tuple(allocator_arg_t __tag, const _Alloc& __a, _U1&& __a1, _U2&& __a2)
: _Inherited(__tag, __a, std::forward<_U1>(__a1),
std::forward<_U2>(__a2)) { }
template<typename _Alloc, typename _U1, typename _U2, typename
enable_if<_TMC::template
_MoveConstructibleTuple<_U1, _U2>()
&& !_TMC::template
_ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
bool>::type = false>
explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
_U1&& __a1, _U2&& __a2)
template<typename _Alloc, typename _U1, typename _U2,
_ExplicitCtor<true, _U1, _U2> = false>
explicit
tuple(allocator_arg_t __tag, const _Alloc& __a,
_U1&& __a1, _U2&& __a2)
: _Inherited(__tag, __a, std::forward<_U1>(__a1),
std::forward<_U2>(__a2)) { }
......@@ -1157,89 +1053,59 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
: _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
template<typename _Alloc, typename _U1, typename _U2, typename
enable_if<_TMC::template
_ConstructibleTuple<_U1, _U2>()
&& _TMC::template
_ImplicitlyConvertibleTuple<_U1, _U2>(),
bool>::type = true>
template<typename _Alloc, typename _U1, typename _U2,
_ImplicitCtor<true, const _U1&, const _U2&> = true>
tuple(allocator_arg_t __tag, const _Alloc& __a,
const tuple<_U1, _U2>& __in)
: _Inherited(__tag, __a,
static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
{ }
template<typename _Alloc, typename _U1, typename _U2, typename
enable_if<_TMC::template
_ConstructibleTuple<_U1, _U2>()
&& !_TMC::template
_ImplicitlyConvertibleTuple<_U1, _U2>(),
bool>::type = false>
explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
template<typename _Alloc, typename _U1, typename _U2,
_ExplicitCtor<true, const _U1&, const _U2&> = false>
explicit
tuple(allocator_arg_t __tag, const _Alloc& __a,
const tuple<_U1, _U2>& __in)
: _Inherited(__tag, __a,
static_cast<const _Tuple_impl<0, _U1, _U2>&>(__in))
{ }
template<typename _Alloc, typename _U1, typename _U2, typename
enable_if<_TMC::template
_MoveConstructibleTuple<_U1, _U2>()
&& _TMC::template
_ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
bool>::type = true>
template<typename _Alloc, typename _U1, typename _U2,
_ImplicitCtor<true, _U1, _U2> = true>
tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
: _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
{ }
template<typename _Alloc, typename _U1, typename _U2, typename
enable_if<_TMC::template
_MoveConstructibleTuple<_U1, _U2>()
&& !_TMC::template
_ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
bool>::type = false>
explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
tuple<_U1, _U2>&& __in)
template<typename _Alloc, typename _U1, typename _U2,
_ExplicitCtor<true, _U1, _U2> = false>
explicit
tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
: _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
{ }
template<typename _Alloc, typename _U1, typename _U2, typename
enable_if<_TMC::template
_ConstructibleTuple<_U1, _U2>()
&& _TMC::template
_ImplicitlyConvertibleTuple<_U1, _U2>(),
bool>::type = true>
tuple(allocator_arg_t __tag, const _Alloc& __a,
template<typename _Alloc, typename _U1, typename _U2,
_ImplicitCtor<true, const _U1&, const _U2&> = true>
tuple(allocator_arg_t __tag, const _Alloc& __a,
const pair<_U1, _U2>& __in)
: _Inherited(__tag, __a, __in.first, __in.second) { }
template<typename _Alloc, typename _U1, typename _U2, typename
enable_if<_TMC::template
_ConstructibleTuple<_U1, _U2>()
&& !_TMC::template
_ImplicitlyConvertibleTuple<_U1, _U2>(),
bool>::type = false>
explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
template<typename _Alloc, typename _U1, typename _U2,
_ExplicitCtor<true, const _U1&, const _U2&> = false>
explicit
tuple(allocator_arg_t __tag, const _Alloc& __a,
const pair<_U1, _U2>& __in)
: _Inherited(__tag, __a, __in.first, __in.second) { }
template<typename _Alloc, typename _U1, typename _U2, typename
enable_if<_TMC::template
_MoveConstructibleTuple<_U1, _U2>()
&& _TMC::template
_ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
bool>::type = true>
tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
template<typename _Alloc, typename _U1, typename _U2,
_ImplicitCtor<true, _U1, _U2> = true>
tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
: _Inherited(__tag, __a, std::forward<_U1>(__in.first),
std::forward<_U2>(__in.second)) { }
template<typename _Alloc, typename _U1, typename _U2, typename
enable_if<_TMC::template
_MoveConstructibleTuple<_U1, _U2>()
&& !_TMC::template
_ImplicitlyMoveConvertibleTuple<_U1, _U2>(),
bool>::type = false>
explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
pair<_U1, _U2>&& __in)
template<typename _Alloc, typename _U1, typename _U2,
_ExplicitCtor<true, _U1, _U2> = false>
explicit
tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
: _Inherited(__tag, __a, std::forward<_U1>(__in.first),
std::forward<_U2>(__in.second)) { }
......
// Copyright (C) 2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-do compile { target c++11 } }
#include <tuple>
#include <memory>
struct X { };
struct Y
{
Y(const std::tuple<X>&) = delete;
Y(std::tuple<X>&&) { throw 1; }
Y(const X&) { }
};
struct Z
{
Z(X&&) { }
Z(const std::tuple<X>&) { throw 1; }
Z(std::tuple<X>&&) = delete;
};
void
test01()
{
// PR libstdc++/90700 wrong constraints on constructor
const std::allocator<int> a;
const std::tuple<X> x;
static_assert(!std::is_convertible<const std::tuple<X>&, Y>::value, "");
static_assert(!std::is_constructible<Y, const std::tuple<X>&>::value, "");
static_assert(!std::is_same<Y, X>::value, "");
// should use tuple<Y>::tuple<X>(allocator_arg_t, const A&, const tuple<X>&)
// and construct Y from X:
std::tuple<Y> y(std::allocator_arg, a, x);
}
void
test02()
{
const std::allocator<int> a;
std::tuple<X> x;
static_assert(!std::is_convertible<std::tuple<X>, Z>::value, "");
static_assert(!std::is_constructible<Z, std::tuple<X>>::value, "");
static_assert(!std::is_same<Z, X>::value, "");
// should use tuple<Z>::tuple<X>(allocator_arg_t, const A&, tuple<X>&&)
// and construct Z from X:
std::tuple<Z> z(std::allocator_arg, a, std::move(x));
}
......@@ -186,12 +186,26 @@ void test03()
struct dr2586
{
using allocator_type = std::allocator<int>;
dr2586() { }
dr2586(std::allocator_arg_t, allocator_type&&) { }
dr2586(const allocator_type&) { }
dr2586(const allocator_type&) : expected(true) { }
bool expected = false;
};
const dr2586::allocator_type a;
std::tuple<dr2586> t{std::allocator_arg, a};
VERIFY( std::get<0>(t).expected );
}
void test04()
{
struct X {
X(std::allocator_arg_t) { }
};
// The element types are not default constructible, so the allocator-extended
// default constructor should not participate in overload resolution.
std::tuple<X, void(&)()> t(std::allocator_arg, *+[]{});
}
int main()
......@@ -199,5 +213,6 @@ int main()
test01();
test02();
test03();
test04();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment