// <tuple> -*- C++ -*-
-// Copyright (C) 2007-2020 Free Software Foundation, Inc.
+// Copyright (C) 2007-2021 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
#include <bits/invoke.h>
#if __cplusplus > 201703L
# include <compare>
+# define __cpp_lib_constexpr_tuple 201811L
#endif
namespace std _GLIBCXX_VISIBILITY(default)
= typename conditional<__is_final(_Tp), false_type,
__is_empty_non_tuple<_Tp>>::type;
- template<std::size_t _Idx, typename _Head,
+ template<size_t _Idx, typename _Head,
bool = __empty_not_final<_Head>::value>
struct _Head_base;
- template<std::size_t _Idx, typename _Head>
+#if __has_cpp_attribute(no_unique_address)
+ template<size_t _Idx, typename _Head>
+ struct _Head_base<_Idx, _Head, true>
+ {
+ constexpr _Head_base()
+ : _M_head_impl() { }
+
+ constexpr _Head_base(const _Head& __h)
+ : _M_head_impl(__h) { }
+
+ constexpr _Head_base(const _Head_base&) = default;
+ constexpr _Head_base(_Head_base&&) = default;
+
+ template<typename _UHead>
+ constexpr _Head_base(_UHead&& __h)
+ : _M_head_impl(std::forward<_UHead>(__h)) { }
+
+ _GLIBCXX20_CONSTEXPR
+ _Head_base(allocator_arg_t, __uses_alloc0)
+ : _M_head_impl() { }
+
+ template<typename _Alloc>
+ _Head_base(allocator_arg_t, __uses_alloc1<_Alloc> __a)
+ : _M_head_impl(allocator_arg, *__a._M_a) { }
+
+ template<typename _Alloc>
+ _Head_base(allocator_arg_t, __uses_alloc2<_Alloc> __a)
+ : _M_head_impl(*__a._M_a) { }
+
+ template<typename _UHead>
+ _GLIBCXX20_CONSTEXPR
+ _Head_base(__uses_alloc0, _UHead&& __uhead)
+ : _M_head_impl(std::forward<_UHead>(__uhead)) { }
+
+ template<typename _Alloc, typename _UHead>
+ _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
+ : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
+ { }
+
+ template<typename _Alloc, typename _UHead>
+ _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
+ : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
+
+ static constexpr _Head&
+ _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
+
+ static constexpr const _Head&
+ _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
+
+ [[__no_unique_address__]] _Head _M_head_impl;
+ };
+#else
+ template<size_t _Idx, typename _Head>
struct _Head_base<_Idx, _Head, true>
: public _Head
{
static constexpr const _Head&
_M_head(const _Head_base& __b) noexcept { return __b; }
};
+#endif
- template<std::size_t _Idx, typename _Head>
+ template<size_t _Idx, typename _Head>
struct _Head_base<_Idx, _Head, false>
{
constexpr _Head_base()
* point in the hierarchy; we use it to implement a constant-time
* get() operation.
*/
- template<std::size_t _Idx, typename... _Elements>
+ template<size_t _Idx, typename... _Elements>
struct _Tuple_impl;
/**
* and derive from a @c Tuple_impl containing the remaining elements
* (which contains the @c Tail).
*/
- template<std::size_t _Idx, typename _Head, typename... _Tail>
+ template<size_t _Idx, typename _Head, typename... _Tail>
struct _Tuple_impl<_Idx, _Head, _Tail...>
: public _Tuple_impl<_Idx + 1, _Tail...>,
private _Head_base<_Idx, _Head>
{
- template<std::size_t, typename...> friend class _Tuple_impl;
+ template<size_t, typename...> friend struct _Tuple_impl;
typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
typedef _Head_base<_Idx, _Head> _Base;
constexpr _Tuple_impl()
: _Inherited(), _Base() { }
- explicit
- constexpr _Tuple_impl(const _Head& __head, const _Tail&... __tail)
- : _Inherited(__tail...), _Base(__head) { }
+ explicit constexpr
+ _Tuple_impl(const _Head& __head, const _Tail&... __tail)
+ : _Inherited(__tail...), _Base(__head)
+ { }
- template<typename _UHead, typename... _UTail, typename = typename
- enable_if<sizeof...(_Tail) == sizeof...(_UTail)>::type>
- explicit
- constexpr _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
+ template<typename _UHead, typename... _UTail,
+ typename = __enable_if_t<sizeof...(_Tail) == sizeof...(_UTail)>>
+ explicit constexpr
+ _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
: _Inherited(std::forward<_UTail>(__tail)...),
- _Base(std::forward<_UHead>(__head)) { }
+ _Base(std::forward<_UHead>(__head))
+ { }
constexpr _Tuple_impl(const _Tuple_impl&) = default;
constexpr
_Tuple_impl(_Tuple_impl&& __in)
noexcept(__and_<is_nothrow_move_constructible<_Head>,
- is_nothrow_move_constructible<_Inherited>>::value)
+ is_nothrow_move_constructible<_Inherited>>::value)
: _Inherited(std::move(_M_tail(__in))),
- _Base(std::forward<_Head>(_M_head(__in))) { }
+ _Base(std::forward<_Head>(_M_head(__in)))
+ { }
template<typename... _UElements>
- constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
+ constexpr
+ _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
: _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
- _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }
+ _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in))
+ { }
template<typename _UHead, typename... _UTails>
- constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
+ constexpr
+ _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
: _Inherited(std::move
(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
_Base(std::forward<_UHead>
- (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }
+ (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
+ { }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
: _Inherited(__tag, __a),
- _Base(__tag, __use_alloc<_Head>(__a)) { }
+ _Base(__tag, __use_alloc<_Head>(__a))
+ { }
template<typename _Alloc>
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
const _Head& __head, const _Tail&... __tail)
: _Inherited(__tag, __a, __tail...),
- _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { }
+ _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head)
+ { }
template<typename _Alloc, typename _UHead, typename... _UTail,
- typename = typename enable_if<sizeof...(_Tail)
- == sizeof...(_UTail)>::type>
+ typename = __enable_if_t<sizeof...(_Tail) == sizeof...(_UTail)>>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
- _UHead&& __head, _UTail&&... __tail)
+ _UHead&& __head, _UTail&&... __tail)
: _Inherited(__tag, __a, std::forward<_UTail>(__tail)...),
- _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
- std::forward<_UHead>(__head)) { }
+ _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
+ std::forward<_UHead>(__head))
+ { }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
- _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
- const _Tuple_impl& __in)
+ _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
+ const _Tuple_impl& __in)
: _Inherited(__tag, __a, _M_tail(__in)),
- _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { }
+ _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in))
+ { }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
- _Tuple_impl&& __in)
+ _Tuple_impl&& __in)
: _Inherited(__tag, __a, std::move(_M_tail(__in))),
_Base(__use_alloc<_Head, _Alloc, _Head>(__a),
- std::forward<_Head>(_M_head(__in))) { }
+ std::forward<_Head>(_M_head(__in)))
+ { }
- template<typename _Alloc, typename... _UElements>
+ template<typename _Alloc, typename _UHead, typename... _UTails>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
- const _Tuple_impl<_Idx, _UElements...>& __in)
+ const _Tuple_impl<_Idx, _UHead, _UTails...>& __in)
: _Inherited(__tag, __a,
- _Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
- _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
- _Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }
+ _Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in)),
+ _Base(__use_alloc<_Head, _Alloc, const _UHead&>(__a),
+ _Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))
+ { }
template<typename _Alloc, typename _UHead, typename... _UTails>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
- _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
+ _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
: _Inherited(__tag, __a, std::move
(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
_Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
- std::forward<_UHead>
- (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }
+ std::forward<_UHead>
+ (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in)))
+ { }
template<typename... _UElements>
_GLIBCXX20_CONSTEXPR
- void
- _M_assign(const _Tuple_impl<_Idx, _UElements...>& __in)
- {
+ void
+ _M_assign(const _Tuple_impl<_Idx, _UElements...>& __in)
+ {
_M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in);
_M_tail(*this)._M_assign(
_Tuple_impl<_Idx, _UElements...>::_M_tail(__in));
template<typename _UHead, typename... _UTails>
_GLIBCXX20_CONSTEXPR
- void
- _M_assign(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
- {
+ void
+ _M_assign(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
+ {
_M_head(*this) = std::forward<_UHead>
(_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in));
_M_tail(*this)._M_assign(
};
// Basis case of inheritance recursion.
- template<std::size_t _Idx, typename _Head>
+ template<size_t _Idx, typename _Head>
struct _Tuple_impl<_Idx, _Head>
: private _Head_base<_Idx, _Head>
{
- template<std::size_t, typename...> friend class _Tuple_impl;
+ template<size_t, typename...> friend struct _Tuple_impl;
typedef _Head_base<_Idx, _Head> _Base;
static constexpr const _Head&
_M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
- constexpr _Tuple_impl()
+ constexpr
+ _Tuple_impl()
: _Base() { }
- explicit
- constexpr _Tuple_impl(const _Head& __head)
- : _Base(__head) { }
+ explicit constexpr
+ _Tuple_impl(const _Head& __head)
+ : _Base(__head)
+ { }
template<typename _UHead>
- explicit
- constexpr _Tuple_impl(_UHead&& __head)
- : _Base(std::forward<_UHead>(__head)) { }
+ explicit constexpr
+ _Tuple_impl(_UHead&& __head)
+ : _Base(std::forward<_UHead>(__head))
+ { }
constexpr _Tuple_impl(const _Tuple_impl&) = default;
constexpr
_Tuple_impl(_Tuple_impl&& __in)
noexcept(is_nothrow_move_constructible<_Head>::value)
- : _Base(std::forward<_Head>(_M_head(__in))) { }
+ : _Base(std::forward<_Head>(_M_head(__in)))
+ { }
template<typename _UHead>
- constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UHead>& __in)
- : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in)) { }
+ constexpr
+ _Tuple_impl(const _Tuple_impl<_Idx, _UHead>& __in)
+ : _Base(_Tuple_impl<_Idx, _UHead>::_M_head(__in))
+ { }
template<typename _UHead>
- constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead>&& __in)
+ constexpr
+ _Tuple_impl(_Tuple_impl<_Idx, _UHead>&& __in)
: _Base(std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
{ }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
- : _Base(__tag, __use_alloc<_Head>(__a)) { }
+ : _Base(__tag, __use_alloc<_Head>(__a))
+ { }
template<typename _Alloc>
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
const _Head& __head)
- : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { }
+ : _Base(__use_alloc<_Head, _Alloc, const _Head&>(__a), __head)
+ { }
template<typename _Alloc, typename _UHead>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
- _UHead&& __head)
+ _UHead&& __head)
: _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
- std::forward<_UHead>(__head)) { }
+ std::forward<_UHead>(__head))
+ { }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
- _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
- const _Tuple_impl& __in)
- : _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { }
+ _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
+ const _Tuple_impl& __in)
+ : _Base(__use_alloc<_Head, _Alloc, const _Head&>(__a), _M_head(__in))
+ { }
template<typename _Alloc>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
- _Tuple_impl&& __in)
+ _Tuple_impl&& __in)
: _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
- std::forward<_Head>(_M_head(__in))) { }
+ std::forward<_Head>(_M_head(__in)))
+ { }
template<typename _Alloc, typename _UHead>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
- const _Tuple_impl<_Idx, _UHead>& __in)
- : _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
- _Tuple_impl<_Idx, _UHead>::_M_head(__in)) { }
+ const _Tuple_impl<_Idx, _UHead>& __in)
+ : _Base(__use_alloc<_Head, _Alloc, const _UHead&>(__a),
+ _Tuple_impl<_Idx, _UHead>::_M_head(__in))
+ { }
template<typename _Alloc, typename _UHead>
_GLIBCXX20_CONSTEXPR
_Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
- _Tuple_impl<_Idx, _UHead>&& __in)
+ _Tuple_impl<_Idx, _UHead>&& __in)
: _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
- std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
+ std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in)))
{ }
template<typename _UHead>
_GLIBCXX20_CONSTEXPR
- void
- _M_assign(const _Tuple_impl<_Idx, _UHead>& __in)
- {
+ void
+ _M_assign(const _Tuple_impl<_Idx, _UHead>& __in)
+ {
_M_head(*this) = _Tuple_impl<_Idx, _UHead>::_M_head(__in);
}
template<typename _UHead>
_GLIBCXX20_CONSTEXPR
- void
- _M_assign(_Tuple_impl<_Idx, _UHead>&& __in)
- {
+ void
+ _M_assign(_Tuple_impl<_Idx, _UHead>&& __in)
+ {
_M_head(*this)
= std::forward<_UHead>(_Tuple_impl<_Idx, _UHead>::_M_head(__in));
}
template<bool, typename... _Types>
struct _TupleConstraints
{
+ template<typename _Tp, typename _Up> // Workaround for PR 96592
+ using is_constructible
+ = __bool_constant<__is_constructible(_Tp, _Up)>;
+
// 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.
/// class tuple_size
template<typename... _Elements>
struct tuple_size<tuple<_Elements...>>
- : public integral_constant<std::size_t, sizeof...(_Elements)> { };
+ : public integral_constant<size_t, sizeof...(_Elements)> { };
#if __cplusplus > 201402L
template <typename _Tp>
* Recursive case for tuple_element: strip off the first element in
* the tuple and retrieve the (i-1)th element of the remaining tuple.
*/
- template<std::size_t __i, typename _Head, typename... _Tail>
+ template<size_t __i, typename _Head, typename... _Tail>
struct tuple_element<__i, tuple<_Head, _Tail...> >
: tuple_element<__i - 1, tuple<_Tail...> > { };
"tuple index is in range");
};
- template<std::size_t __i, typename _Head, typename... _Tail>
+ template<size_t __i, typename _Head, typename... _Tail>
constexpr _Head&
__get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
{ return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
- template<std::size_t __i, typename _Head, typename... _Tail>
+ template<size_t __i, typename _Head, typename... _Tail>
constexpr const _Head&
__get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
{ return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
/// Return a reference to the ith element of a tuple.
- template<std::size_t __i, typename... _Elements>
+ template<size_t __i, typename... _Elements>
constexpr __tuple_element_t<__i, tuple<_Elements...>>&
get(tuple<_Elements...>& __t) noexcept
{ return std::__get_helper<__i>(__t); }
/// Return a const reference to the ith element of a const tuple.
- template<std::size_t __i, typename... _Elements>
+ template<size_t __i, typename... _Elements>
constexpr const __tuple_element_t<__i, tuple<_Elements...>>&
get(const tuple<_Elements...>& __t) noexcept
{ return std::__get_helper<__i>(__t); }
/// Return an rvalue reference to the ith element of a tuple rvalue.
- template<std::size_t __i, typename... _Elements>
+ template<size_t __i, typename... _Elements>
constexpr __tuple_element_t<__i, tuple<_Elements...>>&&
get(tuple<_Elements...>&& __t) noexcept
{
}
/// Return a const rvalue reference to the ith element of a const tuple rvalue.
- template<std::size_t __i, typename... _Elements>
+ template<size_t __i, typename... _Elements>
constexpr const __tuple_element_t<__i, tuple<_Elements...>>&&
get(const tuple<_Elements...>&& __t) noexcept
{
_Tuple, _Nm>
{ };
- template<std::size_t _Nm, typename _Tuple, typename... _Tp>
+ template<size_t _Nm, typename _Tuple, typename... _Tp>
struct __make_tuple_impl<_Nm, tuple<_Tp...>, _Tuple, _Nm>
{
typedef tuple<_Tp...> __type;
template<typename _Tuple>
struct __do_make_tuple
- : __make_tuple_impl<0, tuple<>, _Tuple, std::tuple_size<_Tuple>::value>
+ : __make_tuple_impl<0, tuple<>, _Tuple, tuple_size<_Tuple>::value>
{ };
// Returns the std::tuple equivalent of a tuple-like type.
template<>
struct __make_1st_indices<>
{
- typedef std::_Index_tuple<> __type;
+ typedef _Index_tuple<> __type;
};
template<typename _Tp, typename... _Tpls>
struct __make_1st_indices<_Tp, _Tpls...>
{
- typedef typename std::_Build_index_tuple<std::tuple_size<
- typename std::remove_reference<_Tp>::type>::value>::__type __type;
+ typedef typename _Build_index_tuple<tuple_size<
+ typename remove_reference<_Tp>::type>::value>::__type __type;
};
// Performs the actual concatenation by step-wise expanding tuple-like
template<typename _Ret, typename _Indices, typename... _Tpls>
struct __tuple_concater;
- template<typename _Ret, std::size_t... _Is, typename _Tp, typename... _Tpls>
- struct __tuple_concater<_Ret, std::_Index_tuple<_Is...>, _Tp, _Tpls...>
+ template<typename _Ret, size_t... _Is, typename _Tp, typename... _Tpls>
+ struct __tuple_concater<_Ret, _Index_tuple<_Is...>, _Tp, _Tpls...>
{
template<typename... _Us>
static constexpr _Ret
};
template<typename _Ret>
- struct __tuple_concater<_Ret, std::_Index_tuple<>>
+ struct __tuple_concater<_Ret, _Index_tuple<>>
{
template<typename... _Us>
static constexpr _Ret
{ }
template<class _T1, class _T2>
- template<typename... _Args1, std::size_t... _Indexes1,
- typename... _Args2, std::size_t... _Indexes2>
+ template<typename... _Args1, size_t... _Indexes1,
+ typename... _Args2, size_t... _Indexes2>
_GLIBCXX20_CONSTEXPR inline
pair<_T1, _T2>::
pair(tuple<_Args1...>& __tuple1, tuple<_Args2...>& __tuple2,
_Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>)
: first(std::forward<_Args1>(std::get<_Indexes1>(__tuple1))...),
- second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
+ second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
{ }
#if __cplusplus >= 201703L