mirror of
https://github.com/darlinghq/darling-libcxx.git
synced 2024-11-24 12:29:57 +00:00
f5256e16df
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@103516 91177308-0d34-0410-b5e6-96231b3b80d8
819 lines
26 KiB
C++
819 lines
26 KiB
C++
// -*- C++ -*-
|
|
//===--------------------------- tuple ------------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef _LIBCPP_TUPLE
|
|
#define _LIBCPP_TUPLE
|
|
|
|
/*
|
|
tuple synopsis
|
|
|
|
namespace std
|
|
{
|
|
|
|
template <class... T>
|
|
class tuple {
|
|
public:
|
|
constexpr tuple();
|
|
explicit tuple(const T&...);
|
|
template <class... U>
|
|
explicit tuple(U&&...);
|
|
tuple(const tuple&) = default;
|
|
tuple(tuple&&);
|
|
template <class... U>
|
|
tuple(const tuple<U...>&);
|
|
template <class... U>
|
|
tuple(tuple<U...>&&);
|
|
template <class U1, class U2>
|
|
tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2
|
|
template <class U1, class U2>
|
|
tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2
|
|
|
|
// allocator-extended constructors
|
|
template <class Alloc>
|
|
tuple(allocator_arg_t, const Alloc& a);
|
|
template <class Alloc>
|
|
tuple(allocator_arg_t, const Alloc& a, const T&...);
|
|
template <class Alloc, class... U>
|
|
tuple(allocator_arg_t, const Alloc& a, U&&...);
|
|
template <class Alloc>
|
|
tuple(allocator_arg_t, const Alloc& a, const tuple&);
|
|
template <class Alloc>
|
|
tuple(allocator_arg_t, const Alloc& a, tuple&&);
|
|
template <class Alloc, class... U>
|
|
tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);
|
|
template <class Alloc, class... U>
|
|
tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);
|
|
template <class Alloc, class U1, class U2>
|
|
tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
|
|
template <class Alloc, class U1, class U2>
|
|
tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
|
|
|
|
tuple& operator=(const tuple&);
|
|
tuple& operator=(tuple&&);
|
|
template <class... U>
|
|
tuple& operator=(const tuple<U...>&);
|
|
template <class... U>
|
|
tuple& operator=(tuple<U...>&&);
|
|
template <class U1, class U2>
|
|
tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2
|
|
template <class U1, class U2>
|
|
tuple& operator=(pair<U1, U2>&&); //iffsizeof...(T) == 2
|
|
|
|
void swap(tuple&);
|
|
};
|
|
|
|
const unspecified ignore;
|
|
|
|
template <class... T> tuple<V...> make_tuple(T&&...);
|
|
template <class... T> tuple<T&...> tie(T&...);
|
|
template <class... T, class... U> tuple<T..., U...> tuple_cat(const tuple<T...>&, const tuple<U...>&);
|
|
template <class... T, class... U> tuple<T..., U...> tuple_cat(tuple<T...>&&, const tuple<U...>&);
|
|
template <class... T, class... U> tuple<T..., U...> tuple_cat(const tuple<T...>&, tuple<U...>&&);
|
|
template <class... T, class... U> tuple<T..., U...> tuple_cat(tuple<T...>&&, tuple<U...>&&);
|
|
|
|
// 20.4.1.4, tuple helper classes:
|
|
template <class T> class tuple_size; // undefined
|
|
template <class... T> class tuple_size<tuple<T...>>;
|
|
template <intsize_t I, class T> class tuple_element; // undefined
|
|
template <intsize_t I, class... T> class tuple_element<I, tuple<T...>>;
|
|
|
|
// 20.4.1.5, element access:
|
|
template <intsize_t I, class... T> typename tuple_element<I, tuple<T...>>::type& get(tuple<T...>&);
|
|
template <intsize_t I, class... T> typename tuple_element<I, tuple<T...>>::type const& get(const tuple<T...>&);
|
|
|
|
// 20.4.1.6, relational operators:
|
|
template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&);
|
|
template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&);
|
|
template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&);
|
|
template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&);
|
|
template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&);
|
|
template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&);
|
|
|
|
template <class... Types, class Alloc>
|
|
struct uses_allocator<tuple<Types...>, Alloc>;
|
|
|
|
template <class... Types>
|
|
void swap(tuple<Types...>& x, tuple<Types...>& y);
|
|
|
|
template <class InputIterator>
|
|
InputIterator begin(const std::tuple<InputIterator, InputIterator>& t);
|
|
|
|
template <class InputIterator>
|
|
InputIterator end(const std::tuple<InputIterator, InputIterator>& t);
|
|
|
|
} // std
|
|
|
|
*/
|
|
|
|
#include <__config>
|
|
#include <__tuple>
|
|
#include <cstddef>
|
|
#include <memory>
|
|
#include <type_traits>
|
|
|
|
#pragma GCC system_header
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
|
|
|
// tuple_size
|
|
|
|
template <class ..._Tp>
|
|
class tuple_size<tuple<_Tp...>>
|
|
: public integral_constant<size_t, sizeof...(_Tp)>
|
|
{
|
|
};
|
|
|
|
template <class ..._Tp>
|
|
class tuple_size<const tuple<_Tp...>>
|
|
: public integral_constant<size_t, sizeof...(_Tp)>
|
|
{
|
|
};
|
|
|
|
// tuple_element
|
|
|
|
template <size_t _Ip, class ..._Tp>
|
|
class tuple_element<_Ip, tuple<_Tp...>>
|
|
{
|
|
public:
|
|
typedef typename tuple_element<_Ip, __tuple_types<_Tp...>>::type type;
|
|
};
|
|
|
|
template <size_t _Ip, class ..._Tp>
|
|
class tuple_element<_Ip, const tuple<_Tp...>>
|
|
{
|
|
public:
|
|
typedef const typename tuple_element<_Ip, __tuple_types<_Tp...>>::type type;
|
|
};
|
|
|
|
// __tuple_leaf
|
|
|
|
template <size_t _Ip, class _Hp, bool=is_empty<_Hp>::value>
|
|
class __tuple_leaf;
|
|
|
|
template <size_t _Ip, class _Hp, bool _Ep>
|
|
inline
|
|
void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
|
|
{
|
|
swap(__x.get(), __y.get());
|
|
}
|
|
|
|
template <size_t _Ip, class _Hp, bool>
|
|
class __tuple_leaf
|
|
{
|
|
_Hp value;
|
|
|
|
__tuple_leaf& operator=(const __tuple_leaf&);
|
|
public:
|
|
_LIBCPP_INLINE_VISIBILITY __tuple_leaf() : value()
|
|
{static_assert(!is_reference<_Hp>::value,
|
|
"Attempted to default construct a reference element in a tuple");}
|
|
|
|
template <class _Alloc>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
__tuple_leaf(integral_constant<int, 0>, const _Alloc&)
|
|
: value()
|
|
{static_assert(!is_reference<_Hp>::value,
|
|
"Attempted to default construct a reference element in a tuple");}
|
|
|
|
template <class _Alloc>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
__tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
|
|
: value(allocator_arg_t(), __a)
|
|
{static_assert(!is_reference<_Hp>::value,
|
|
"Attempted to default construct a reference element in a tuple");}
|
|
|
|
template <class _Alloc>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
__tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
|
|
: value(__a)
|
|
{static_assert(!is_reference<_Hp>::value,
|
|
"Attempted to default construct a reference element in a tuple");}
|
|
|
|
template <class _Tp>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
explicit __tuple_leaf(_Tp&& __t)
|
|
: value(_STD::forward<_Tp>(__t))
|
|
{static_assert(!is_lvalue_reference<_Hp>::value ||
|
|
is_lvalue_reference<_Hp>::value &&
|
|
(is_lvalue_reference<_Tp>::value ||
|
|
is_same<typename remove_reference<_Tp>::type,
|
|
reference_wrapper<
|
|
typename remove_reference<_Hp>::type
|
|
>
|
|
>::value),
|
|
"Attempted to construct a reference element in a tuple with an rvalue");}
|
|
|
|
template <class _Tp, class _Alloc>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
|
|
: value(_STD::forward<_Tp>(__t))
|
|
{static_assert(!is_lvalue_reference<_Hp>::value ||
|
|
is_lvalue_reference<_Hp>::value &&
|
|
(is_lvalue_reference<_Tp>::value ||
|
|
is_same<typename remove_reference<_Tp>::type,
|
|
reference_wrapper<
|
|
typename remove_reference<_Hp>::type
|
|
>
|
|
>::value),
|
|
"Attempted to construct a reference element in a tuple with an rvalue");}
|
|
|
|
template <class _Tp, class _Alloc>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
|
|
: value(allocator_arg_t(), __a, _STD::forward<_Tp>(__t))
|
|
{static_assert(!is_lvalue_reference<_Hp>::value ||
|
|
is_lvalue_reference<_Hp>::value &&
|
|
(is_lvalue_reference<_Tp>::value ||
|
|
is_same<typename remove_reference<_Tp>::type,
|
|
reference_wrapper<
|
|
typename remove_reference<_Hp>::type
|
|
>
|
|
>::value),
|
|
"Attempted to construct a reference element in a tuple with an rvalue");}
|
|
|
|
template <class _Tp, class _Alloc>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
|
|
: value(_STD::forward<_Tp>(__t), __a)
|
|
{static_assert(!is_lvalue_reference<_Hp>::value ||
|
|
is_lvalue_reference<_Hp>::value &&
|
|
(is_lvalue_reference<_Tp>::value ||
|
|
is_same<typename remove_reference<_Tp>::type,
|
|
reference_wrapper<
|
|
typename remove_reference<_Hp>::type
|
|
>
|
|
>::value),
|
|
"Attempted to construct a reference element in a tuple with an rvalue");}
|
|
|
|
template <class _Tp>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t)
|
|
: value(__t.get()) {}
|
|
|
|
template <class _Tp>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
__tuple_leaf&
|
|
operator=(_Tp&& __t)
|
|
{
|
|
value = _STD::forward<_Tp>(__t);
|
|
return *this;
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
int swap(__tuple_leaf& __t)
|
|
{
|
|
_STD::swap(*this, __t);
|
|
return 0;
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _Hp& get() {return value;}
|
|
_LIBCPP_INLINE_VISIBILITY const _Hp& get() const {return value;}
|
|
};
|
|
|
|
template <size_t _Ip, class _Hp>
|
|
class __tuple_leaf<_Ip, _Hp, true>
|
|
: private _Hp
|
|
{
|
|
|
|
__tuple_leaf& operator=(const __tuple_leaf&);
|
|
public:
|
|
_LIBCPP_INLINE_VISIBILITY __tuple_leaf() {}
|
|
|
|
template <class _Alloc>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
__tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
|
|
|
|
template <class _Alloc>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
__tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
|
|
: _Hp(allocator_arg_t(), __a) {}
|
|
|
|
template <class _Alloc>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
__tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
|
|
: _Hp(__a) {}
|
|
|
|
template <class _Tp>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
explicit __tuple_leaf(_Tp&& __t)
|
|
: _Hp(_STD::forward<_Tp>(__t)) {}
|
|
|
|
template <class _Tp, class _Alloc>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
|
|
: _Hp(_STD::forward<_Tp>(__t)) {}
|
|
|
|
template <class _Tp, class _Alloc>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
|
|
: _Hp(allocator_arg_t(), __a, _STD::forward<_Tp>(__t)) {}
|
|
|
|
template <class _Tp, class _Alloc>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
|
|
: _Hp(_STD::forward<_Tp>(__t), __a) {}
|
|
|
|
template <class _Tp>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
explicit __tuple_leaf(const __tuple_leaf<_Ip, _Tp>& __t)
|
|
: _Hp(__t.get()) {}
|
|
|
|
template <class _Tp>
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
__tuple_leaf&
|
|
operator=(_Tp&& __t)
|
|
{
|
|
_Hp::operator=(_STD::forward<_Tp>(__t));
|
|
return *this;
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY int swap(__tuple_leaf& __t)
|
|
{
|
|
_STD::swap(*this, __t);
|
|
return 0;
|
|
}
|
|
|
|
_LIBCPP_INLINE_VISIBILITY _Hp& get() {return static_cast<_Hp&>(*this);}
|
|
_LIBCPP_INLINE_VISIBILITY const _Hp& get() const {return static_cast<const _Hp&>(*this);}
|
|
};
|
|
|
|
template <class ..._Tp> void __swallow(_Tp&&...) {}
|
|
|
|
// __tuple_impl
|
|
|
|
template<class _Indx, class ..._Tp> struct __tuple_impl;
|
|
|
|
template<size_t ..._Indx, class ..._Tp>
|
|
struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
|
|
: public __tuple_leaf<_Indx, _Tp>...
|
|
{
|
|
template <size_t ..._Uf, class ..._Tf,
|
|
size_t ..._Ul, class ..._Tl, class ..._Up>
|
|
explicit
|
|
__tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
|
|
__tuple_indices<_Ul...>, __tuple_types<_Tl...>,
|
|
_Up&&... __u) :
|
|
__tuple_leaf<_Uf, _Tf>(_STD::forward<_Up>(__u))...,
|
|
__tuple_leaf<_Ul, _Tl>()...
|
|
{}
|
|
|
|
template <class _Alloc, size_t ..._Uf, class ..._Tf,
|
|
size_t ..._Ul, class ..._Tl, class ..._Up>
|
|
explicit
|
|
__tuple_impl(allocator_arg_t, const _Alloc& __a,
|
|
__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
|
|
__tuple_indices<_Ul...>, __tuple_types<_Tl...>,
|
|
_Up&&... __u) :
|
|
__tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
|
|
_STD::forward<_Up>(__u))...,
|
|
__tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
|
|
{}
|
|
|
|
template <class _Tuple,
|
|
class = typename enable_if
|
|
<
|
|
__tuple_convertible<_Tuple, tuple<_Tp...>>::value
|
|
>::type
|
|
>
|
|
__tuple_impl(_Tuple&& __t)
|
|
: __tuple_leaf<_Indx, _Tp>(_STD::forward<typename tuple_element<_Indx,
|
|
typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))...
|
|
{}
|
|
|
|
template <class _Alloc, class _Tuple,
|
|
class = typename enable_if
|
|
<
|
|
__tuple_convertible<_Tuple, tuple<_Tp...>>::value
|
|
>::type
|
|
>
|
|
__tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
|
|
: __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
|
|
typename __make_tuple_types<_Tuple>::type>::type>(), __a,
|
|
_STD::forward<typename tuple_element<_Indx,
|
|
typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))...
|
|
{}
|
|
|
|
template <class _Tuple>
|
|
typename enable_if
|
|
<
|
|
__tuple_assignable<_Tuple, tuple<_Tp...>>::value,
|
|
__tuple_impl&
|
|
>::type
|
|
operator=(_Tuple&& __t)
|
|
{
|
|
__swallow(__tuple_leaf<_Indx, _Tp>::operator=(_STD::forward<typename tuple_element<_Indx,
|
|
typename __make_tuple_types<_Tuple>::type>::type>(_STD::get<_Indx>(__t)))...);
|
|
return *this;
|
|
}
|
|
|
|
void swap(__tuple_impl& __t)
|
|
{
|
|
__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
|
|
}
|
|
};
|
|
|
|
template <class ..._Tp>
|
|
class tuple
|
|
{
|
|
typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> base;
|
|
|
|
base base_;
|
|
|
|
template <size_t _Jp, class ..._Up> friend
|
|
typename tuple_element<_Jp, tuple<_Up...>>::type& get(tuple<_Up...>&);
|
|
template <size_t _Jp, class ..._Up> friend
|
|
const typename tuple_element<_Jp, tuple<_Up...>>::type& get(const tuple<_Up...>&);
|
|
public:
|
|
|
|
explicit tuple(const _Tp& ... __t)
|
|
: base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
|
|
typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
|
|
typename __make_tuple_indices<0>::type(),
|
|
typename __make_tuple_types<tuple, 0>::type(),
|
|
__t...
|
|
) {}
|
|
|
|
template <class _Alloc>
|
|
tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
|
|
: base_(allocator_arg_t(), __a,
|
|
typename __make_tuple_indices<sizeof...(_Tp)>::type(),
|
|
typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
|
|
typename __make_tuple_indices<0>::type(),
|
|
typename __make_tuple_types<tuple, 0>::type(),
|
|
__t...
|
|
) {}
|
|
|
|
template <class ..._Up,
|
|
class = typename enable_if
|
|
<
|
|
sizeof...(_Up) <= sizeof...(_Tp) &&
|
|
__tuple_convertible
|
|
<
|
|
tuple<_Up...>,
|
|
typename __make_tuple_types<tuple,
|
|
sizeof...(_Up) < sizeof...(_Tp) ?
|
|
sizeof...(_Up) :
|
|
sizeof...(_Tp)>::type
|
|
>::value
|
|
>::type
|
|
>
|
|
explicit
|
|
tuple(_Up&&... __u)
|
|
: base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
|
|
typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
|
|
typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
|
|
typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
|
|
_STD::forward<_Up>(__u)...) {}
|
|
|
|
template <class _Alloc, class ..._Up,
|
|
class = typename enable_if
|
|
<
|
|
sizeof...(_Up) <= sizeof...(_Tp) &&
|
|
__tuple_convertible
|
|
<
|
|
tuple<_Up...>,
|
|
typename __make_tuple_types<tuple,
|
|
sizeof...(_Up) < sizeof...(_Tp) ?
|
|
sizeof...(_Up) :
|
|
sizeof...(_Tp)>::type
|
|
>::value
|
|
>::type
|
|
>
|
|
tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
|
|
: base_(allocator_arg_t(), __a,
|
|
typename __make_tuple_indices<sizeof...(_Up)>::type(),
|
|
typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
|
|
typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
|
|
typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
|
|
_STD::forward<_Up>(__u)...) {}
|
|
|
|
template <class _Tuple,
|
|
class = typename enable_if
|
|
<
|
|
__tuple_convertible<_Tuple, tuple>::value
|
|
>::type
|
|
>
|
|
tuple(_Tuple&& __t)
|
|
: base_(_STD::forward<_Tuple>(__t)) {}
|
|
|
|
template <class _Alloc, class _Tuple,
|
|
class = typename enable_if
|
|
<
|
|
__tuple_convertible<_Tuple, tuple>::value
|
|
>::type
|
|
>
|
|
tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
|
|
: base_(allocator_arg_t(), __a, _STD::forward<_Tuple>(__t)) {}
|
|
|
|
template <class _Tuple,
|
|
class = typename enable_if
|
|
<
|
|
__tuple_assignable<_Tuple, tuple>::value
|
|
>::type
|
|
>
|
|
tuple&
|
|
operator=(_Tuple&& __t)
|
|
{
|
|
base_.operator=(_STD::forward<_Tuple>(__t));
|
|
return *this;
|
|
}
|
|
|
|
void swap(tuple& __t) {base_.swap(__t.base_);}
|
|
};
|
|
|
|
template <>
|
|
class tuple<>
|
|
{
|
|
public:
|
|
tuple() {}
|
|
template <class _Alloc>
|
|
tuple(allocator_arg_t, const _Alloc&) {}
|
|
template <class _Alloc>
|
|
tuple(allocator_arg_t, const _Alloc&, const tuple&) {}
|
|
template <class _U>
|
|
tuple(array<_U, 0>) {}
|
|
template <class _Alloc, class _U>
|
|
tuple(allocator_arg_t, const _Alloc&, array<_U, 0>) {}
|
|
void swap(tuple&) {}
|
|
};
|
|
|
|
template <class ..._Tp>
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
void
|
|
swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) {__t.swap(__u);}
|
|
|
|
// get
|
|
|
|
template <size_t _Ip, class ..._Tp>
|
|
inline
|
|
typename tuple_element<_Ip, tuple<_Tp...>>::type&
|
|
get(tuple<_Tp...>& __t)
|
|
{
|
|
typedef typename tuple_element<_Ip, tuple<_Tp...>>::type type;
|
|
return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get();
|
|
}
|
|
|
|
template <size_t _Ip, class ..._Tp>
|
|
inline
|
|
const typename tuple_element<_Ip, tuple<_Tp...>>::type&
|
|
get(const tuple<_Tp...>& __t)
|
|
{
|
|
typedef typename tuple_element<_Ip, tuple<_Tp...>>::type type;
|
|
return static_cast<const __tuple_leaf<_Ip, type>&>(__t.base_).get();
|
|
}
|
|
|
|
// tie
|
|
|
|
template <class ..._Tp>
|
|
inline
|
|
tuple<_Tp&...>
|
|
tie(_Tp&... __t)
|
|
{
|
|
return tuple<_Tp&...>(__t...);
|
|
}
|
|
|
|
template <class _Up>
|
|
struct __ignore_t
|
|
{
|
|
__ignore_t() {}
|
|
template <class _Tp>
|
|
__ignore_t(_Tp&&) {}
|
|
template <class _Tp>
|
|
const __ignore_t& operator=(_Tp&&) const {return *this;}
|
|
};
|
|
|
|
namespace { const __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); }
|
|
|
|
template <class _Tp> class reference_wrapper;
|
|
|
|
template <class _Tp>
|
|
struct ___make_tuple_return
|
|
{
|
|
typedef _Tp type;
|
|
};
|
|
|
|
template <class _Tp>
|
|
struct ___make_tuple_return<reference_wrapper<_Tp>>
|
|
{
|
|
typedef _Tp& type;
|
|
};
|
|
|
|
template <class _Tp>
|
|
struct __make_tuple_return
|
|
{
|
|
typedef typename ___make_tuple_return<typename decay<_Tp>::type>::type type;
|
|
};
|
|
|
|
template <class... _Tp>
|
|
inline
|
|
tuple<typename __make_tuple_return<_Tp>::type...>
|
|
make_tuple(_Tp&&... __t)
|
|
{
|
|
return tuple<typename __make_tuple_return<_Tp>::type...>(_STD::forward<_Tp>(__t)...);
|
|
}
|
|
|
|
template <size_t _I>
|
|
struct __tuple_equal
|
|
{
|
|
template <class _Tp, class _Up>
|
|
bool operator()(const _Tp& __x, const _Up& __y)
|
|
{
|
|
return __tuple_equal<_I - 1>()(__x, __y) && get<_I-1>(__x) == get<_I-1>(__y);
|
|
}
|
|
};
|
|
|
|
template <>
|
|
struct __tuple_equal<0>
|
|
{
|
|
template <class _Tp, class _Up>
|
|
bool operator()(const _Tp&, const _Up&)
|
|
{
|
|
return true;
|
|
}
|
|
};
|
|
|
|
template <class ..._Tp, class ..._Up>
|
|
inline
|
|
bool
|
|
operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
|
|
{
|
|
return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
|
|
}
|
|
|
|
template <class ..._Tp, class ..._Up>
|
|
inline
|
|
bool
|
|
operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
|
|
{
|
|
return !(__x == __y);
|
|
}
|
|
|
|
template <size_t _I>
|
|
struct __tuple_less
|
|
{
|
|
template <class _Tp, class _Up>
|
|
bool operator()(const _Tp& __x, const _Up& __y)
|
|
{
|
|
return __tuple_less<_I-1>()(__x, __y) ||
|
|
(!__tuple_less<_I-1>()(__y, __x) && get<_I-1>(__x) < get<_I-1>(__y));
|
|
}
|
|
};
|
|
|
|
template <>
|
|
struct __tuple_less<0>
|
|
{
|
|
template <class _Tp, class _Up>
|
|
bool operator()(const _Tp&, const _Up&)
|
|
{
|
|
return false;
|
|
}
|
|
};
|
|
|
|
template <class ..._Tp, class ..._Up>
|
|
inline
|
|
bool
|
|
operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
|
|
{
|
|
return __tuple_less<sizeof...(_Tp)>()(__x, __y);
|
|
}
|
|
|
|
template <class ..._Tp, class ..._Up>
|
|
inline
|
|
bool
|
|
operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
|
|
{
|
|
return __y < __x;
|
|
}
|
|
|
|
template <class ..._Tp, class ..._Up>
|
|
inline
|
|
bool
|
|
operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
|
|
{
|
|
return !(__x < __y);
|
|
}
|
|
|
|
template <class ..._Tp, class ..._Up>
|
|
inline
|
|
bool
|
|
operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
|
|
{
|
|
return !(__y < __x);
|
|
}
|
|
|
|
// tuple_cat
|
|
|
|
template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
|
|
inline
|
|
tuple<_Tp..., _Up...>
|
|
__tuple_cat(const tuple<_Tp...>& __x, __tuple_indices<_I1...>, const tuple<_Up...>& __y, __tuple_indices<_I2...>)
|
|
{
|
|
return tuple<_Tp..., _Up...>(get<_I1>(__x)..., get<_I2>(__y)...);
|
|
}
|
|
|
|
template <class... _Tp, class... _Up>
|
|
inline
|
|
tuple<_Tp..., _Up...>
|
|
tuple_cat(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
|
|
{
|
|
return __tuple_cat(__x, typename __make_tuple_indices<sizeof...(_Tp)>::type(),
|
|
__y, typename __make_tuple_indices<sizeof...(_Up)>::type());
|
|
}
|
|
|
|
template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
|
|
inline
|
|
tuple<_Tp..., _Up...>
|
|
__tuple_cat(tuple<_Tp...>&& __x, __tuple_indices<_I1...>, const tuple<_Up...>& __y, __tuple_indices<_I2...>)
|
|
{
|
|
return tuple<_Tp..., _Up...>(_STD::forward<_Tp>(get<_I1>(__x))..., get<_I2>(__y)...);
|
|
}
|
|
|
|
template <class... _Tp, class... _Up>
|
|
inline
|
|
tuple<_Tp..., _Up...>
|
|
tuple_cat(tuple<_Tp...>&& __x, const tuple<_Up...>& __y)
|
|
{
|
|
return __tuple_cat(_STD::move(__x), typename __make_tuple_indices<sizeof...(_Tp)>::type(),
|
|
__y, typename __make_tuple_indices<sizeof...(_Up)>::type());
|
|
}
|
|
|
|
template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
|
|
inline
|
|
tuple<_Tp..., _Up...>
|
|
__tuple_cat(const tuple<_Tp...>& __x, __tuple_indices<_I1...>, tuple<_Up...>&& __y, __tuple_indices<_I2...>)
|
|
{
|
|
return tuple<_Tp..., _Up...>(get<_I1>(__x)..., _STD::forward<_Up>(get<_I2>(__y))...);
|
|
}
|
|
|
|
template <class... _Tp, class... _Up>
|
|
inline
|
|
tuple<_Tp..., _Up...>
|
|
tuple_cat(const tuple<_Tp...>& __x, tuple<_Up...>&& __y)
|
|
{
|
|
return __tuple_cat(__x, typename __make_tuple_indices<sizeof...(_Tp)>::type(),
|
|
_STD::move(__y), typename __make_tuple_indices<sizeof...(_Up)>::type());
|
|
}
|
|
|
|
template <class... _Tp, size_t ..._I1, class... _Up, size_t ..._I2>
|
|
inline
|
|
tuple<_Tp..., _Up...>
|
|
__tuple_cat(tuple<_Tp...>&& __x, __tuple_indices<_I1...>, tuple<_Up...>&& __y, __tuple_indices<_I2...>)
|
|
{
|
|
return tuple<_Tp..., _Up...>(_STD::forward<_Tp>(get<_I1>(__x))..., _STD::forward<_Up>(get<_I2>(__y))...);
|
|
}
|
|
|
|
template <class... _Tp, class... _Up>
|
|
inline
|
|
tuple<_Tp..., _Up...>
|
|
tuple_cat(tuple<_Tp...>&& __x, tuple<_Up...>&& __y)
|
|
{
|
|
return __tuple_cat(_STD::move(__x), typename __make_tuple_indices<sizeof...(_Tp)>::type(),
|
|
_STD::move(__y), typename __make_tuple_indices<sizeof...(_Up)>::type());
|
|
}
|
|
|
|
template <class ..._Tp, class _Alloc>
|
|
struct uses_allocator<tuple<_Tp...>, _Alloc>
|
|
: true_type {};
|
|
|
|
template <class _InputIterator>
|
|
inline
|
|
_InputIterator
|
|
begin(const std::tuple<_InputIterator, _InputIterator>& __t)
|
|
{
|
|
return get<0>(__t);
|
|
}
|
|
|
|
template <class _InputIterator>
|
|
inline
|
|
_InputIterator
|
|
end(const std::tuple<_InputIterator, _InputIterator>& __t)
|
|
{
|
|
return get<1>(__t);
|
|
}
|
|
|
|
template <class _T1, class _T2>
|
|
template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
pair<_T1, _T2>::pair(piecewise_construct_t,
|
|
tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
|
|
__tuple_indices<_I1...>, __tuple_indices<_I2...>)
|
|
: first(_STD::forward<_Args1>(get<_I1>( __first_args))...),
|
|
second(_STD::forward<_Args2>(get<_I2>(__second_args))...)
|
|
{
|
|
}
|
|
|
|
#endif
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
#endif // _LIBCPP_TUPLE
|