From fe1ccca2776129541f1c4f645e4d1de89a22a031 Mon Sep 17 00:00:00 2001 From: patrick Date: Sat, 3 Sep 2016 18:39:32 +0000 Subject: Import libc++ 3.9.0 --- lib/libcxx/include/tuple | 1418 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1418 insertions(+) create mode 100644 lib/libcxx/include/tuple (limited to 'lib/libcxx/include/tuple') diff --git a/lib/libcxx/include/tuple b/lib/libcxx/include/tuple new file mode 100644 index 00000000000..6805d8c7635 --- /dev/null +++ b/lib/libcxx/include/tuple @@ -0,0 +1,1418 @@ +// -*- 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 tuple { +public: + constexpr tuple(); + explicit tuple(const T&...); // constexpr in C++14 + template + explicit tuple(U&&...); // constexpr in C++14 + tuple(const tuple&) = default; + tuple(tuple&&) = default; + template + tuple(const tuple&); // constexpr in C++14 + template + tuple(tuple&&); // constexpr in C++14 + template + tuple(const pair&); // iff sizeof...(T) == 2 // constexpr in C++14 + template + tuple(pair&&); // iff sizeof...(T) == 2 // constexpr in C++14 + + // allocator-extended constructors + template + tuple(allocator_arg_t, const Alloc& a); + template + tuple(allocator_arg_t, const Alloc& a, const T&...); + template + tuple(allocator_arg_t, const Alloc& a, U&&...); + template + tuple(allocator_arg_t, const Alloc& a, const tuple&); + template + tuple(allocator_arg_t, const Alloc& a, tuple&&); + template + tuple(allocator_arg_t, const Alloc& a, const tuple&); + template + tuple(allocator_arg_t, const Alloc& a, tuple&&); + template + tuple(allocator_arg_t, const Alloc& a, const pair&); + template + tuple(allocator_arg_t, const Alloc& a, pair&&); + + tuple& operator=(const tuple&); + tuple& + operator=(tuple&&) noexcept(AND(is_nothrow_move_assignable::value ...)); + template + tuple& operator=(const tuple&); + template + tuple& operator=(tuple&&); + template + tuple& operator=(const pair&); // iff sizeof...(T) == 2 + template + tuple& operator=(pair&&); //iffsizeof...(T) == 2 + + void swap(tuple&) noexcept(AND(swap(declval(), declval())...)); +}; + +const unspecified ignore; + +template tuple make_tuple(T&&...); // constexpr in C++14 +template tuple forward_as_tuple(T&&...) noexcept; // constexpr in C++14 +template tuple tie(T&...) noexcept; // constexpr in C++14 +template tuple tuple_cat(Tuples&&... tpls); // constexpr in C++14 + +// [tuple.apply], calling a function with a tuple of arguments: +template + constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17 +template + constexpr T make_from_tuple(Tuple&& t); // C++17 + +// 20.4.1.4, tuple helper classes: +template class tuple_size; // undefined +template class tuple_size>; +template + constexpr size_t tuple_size_v = tuple_size::value; // C++17 +template class tuple_element; // undefined +template class tuple_element>; +template + using tuple_element_t = typename tuple_element ::type; // C++14 + +// 20.4.1.5, element access: +template + typename tuple_element>::type& + get(tuple&) noexcept; // constexpr in C++14 +template + const typename tuple_element>::type& + get(const tuple&) noexcept; // constexpr in C++14 +template + typename tuple_element>::type&& + get(tuple&&) noexcept; // constexpr in C++14 +template + const typename tuple_element>::type&& + get(const tuple&&) noexcept; // constexpr in C++14 + +template + constexpr T1& get(tuple&) noexcept; // C++14 +template + constexpr const T1& get(const tuple&) noexcept; // C++14 +template + constexpr T1&& get(tuple&&) noexcept; // C++14 +template + constexpr const T1&& get(const tuple&&) noexcept; // C++14 + +// 20.4.1.6, relational operators: +template bool operator==(const tuple&, const tuple&); // constexpr in C++14 +template bool operator<(const tuple&, const tuple&); // constexpr in C++14 +template bool operator!=(const tuple&, const tuple&); // constexpr in C++14 +template bool operator>(const tuple&, const tuple&); // constexpr in C++14 +template bool operator<=(const tuple&, const tuple&); // constexpr in C++14 +template bool operator>=(const tuple&, const tuple&); // constexpr in C++14 + +template + struct uses_allocator, Alloc>; + +template + void + swap(tuple& x, tuple& y) noexcept(noexcept(x.swap(y))); + +} // std + +*/ + +#include <__config> +#include <__tuple> +#include +#include +#include <__functional_base> +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +// tuple_size + +template +class _LIBCPP_TYPE_VIS_ONLY tuple_size > + : public integral_constant +{ +}; + +// tuple_element + +template +class _LIBCPP_TYPE_VIS_ONLY tuple_element<_Ip, tuple<_Tp...> > +{ +public: + typedef typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type; +}; + +#if _LIBCPP_STD_VER > 11 +template +using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type; +#endif + +// __tuple_leaf + +template ::value && !__libcpp_is_final<_Hp>::value + > +class __tuple_leaf; + +template +inline _LIBCPP_INLINE_VISIBILITY +void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y) + _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value) +{ + swap(__x.get(), __y.get()); +} + +template +class __tuple_leaf +{ + _Hp value; + + __tuple_leaf& operator=(const __tuple_leaf&); +public: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf() + _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : value() + {static_assert(!is_reference<_Hp>::value, + "Attempted to default construct a reference element in a tuple");} + + template + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf(integral_constant, const _Alloc&) + : value() + {static_assert(!is_reference<_Hp>::value, + "Attempted to default construct a reference element in a tuple");} + + template + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf(integral_constant, 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 + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf(integral_constant, const _Alloc& __a) + : value(__a) + {static_assert(!is_reference<_Hp>::value, + "Attempted to default construct a reference element in a tuple");} + + template ::type, __tuple_leaf>> + , is_constructible<_Hp, _Tp> + >::value + >::type + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) + : value(_VSTD::forward<_Tp>(__t)) + {static_assert(!is_reference<_Hp>::value || + (is_lvalue_reference<_Hp>::value && + (is_lvalue_reference<_Tp>::value || + is_same::type, + reference_wrapper< + typename remove_reference<_Hp>::type + > + >::value)) || + (is_rvalue_reference<_Hp>::value && + !is_lvalue_reference<_Tp>::value), + "Attempted to construct a reference element in a tuple with an rvalue");} + + template + _LIBCPP_INLINE_VISIBILITY + explicit __tuple_leaf(integral_constant, const _Alloc&, _Tp&& __t) + : value(_VSTD::forward<_Tp>(__t)) + {static_assert(!is_lvalue_reference<_Hp>::value || + (is_lvalue_reference<_Hp>::value && + (is_lvalue_reference<_Tp>::value || + is_same::type, + reference_wrapper< + typename remove_reference<_Hp>::type + > + >::value)), + "Attempted to construct a reference element in a tuple with an rvalue");} + + template + _LIBCPP_INLINE_VISIBILITY + explicit __tuple_leaf(integral_constant, const _Alloc& __a, _Tp&& __t) + : value(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) + {static_assert(!is_lvalue_reference<_Hp>::value || + (is_lvalue_reference<_Hp>::value && + (is_lvalue_reference<_Tp>::value || + is_same::type, + reference_wrapper< + typename remove_reference<_Hp>::type + > + >::value)), + "Attempted to construct a reference element in a tuple with an rvalue");} + + template + _LIBCPP_INLINE_VISIBILITY + explicit __tuple_leaf(integral_constant, const _Alloc& __a, _Tp&& __t) + : value(_VSTD::forward<_Tp>(__t), __a) + {static_assert(!is_lvalue_reference<_Hp>::value || + (is_lvalue_reference<_Hp>::value && + (is_lvalue_reference<_Tp>::value || + is_same::type, + reference_wrapper< + typename remove_reference<_Hp>::type + > + >::value)), + "Attempted to construct a reference element in a tuple with an rvalue");} + + __tuple_leaf(const __tuple_leaf& __t) = default; + __tuple_leaf(__tuple_leaf&& __t) = default; + + template + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf& + operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value)) + { + value = _VSTD::forward<_Tp>(__t); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value) + { + _VSTD::swap(*this, __t); + return 0; + } + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return value;} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return value;} +}; + +template +class __tuple_leaf<_Ip, _Hp, true> + : private _Hp +{ + + __tuple_leaf& operator=(const __tuple_leaf&); +public: + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf() + _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {} + + template + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf(integral_constant, const _Alloc&) {} + + template + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf(integral_constant, const _Alloc& __a) + : _Hp(allocator_arg_t(), __a) {} + + template + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf(integral_constant, const _Alloc& __a) + : _Hp(__a) {} + + template ::type, __tuple_leaf>> + , is_constructible<_Hp, _Tp> + >::value + >::type + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) + : _Hp(_VSTD::forward<_Tp>(__t)) {} + + template + _LIBCPP_INLINE_VISIBILITY + explicit __tuple_leaf(integral_constant, const _Alloc&, _Tp&& __t) + : _Hp(_VSTD::forward<_Tp>(__t)) {} + + template + _LIBCPP_INLINE_VISIBILITY + explicit __tuple_leaf(integral_constant, const _Alloc& __a, _Tp&& __t) + : _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {} + + template + _LIBCPP_INLINE_VISIBILITY + explicit __tuple_leaf(integral_constant, const _Alloc& __a, _Tp&& __t) + : _Hp(_VSTD::forward<_Tp>(__t), __a) {} + + __tuple_leaf(__tuple_leaf const &) = default; + __tuple_leaf(__tuple_leaf &&) = default; + + template + _LIBCPP_INLINE_VISIBILITY + __tuple_leaf& + operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value)) + { + _Hp::operator=(_VSTD::forward<_Tp>(__t)); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + int + swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value) + { + _VSTD::swap(*this, __t); + return 0; + } + + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);} + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast(*this);} +}; + +template +_LIBCPP_INLINE_VISIBILITY +void __swallow(_Tp&&...) _NOEXCEPT {} + +template +struct __lazy_all : __all<_Tp::value...> {}; + +template +struct __all_default_constructible; + +template +struct __all_default_constructible<__tuple_types<_Tp...>> + : __all::value...> +{ }; + +// __tuple_impl + +template struct __tuple_impl; + +template +struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...> + : public __tuple_leaf<_Indx, _Tp>... +{ + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR __tuple_impl() + _NOEXCEPT_(__all::value...>::value) {} + + template + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit + __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>, + __tuple_indices<_Ul...>, __tuple_types<_Tl...>, + _Up&&... __u) + _NOEXCEPT_((__all::value...>::value && + __all::value...>::value)) : + __tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))..., + __tuple_leaf<_Ul, _Tl>()... + {} + + template + _LIBCPP_INLINE_VISIBILITY + 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, + _VSTD::forward<_Up>(__u))..., + __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)... + {} + + template >::value + >::type + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all::type>::type>::value...>::value)) + : __tuple_leaf<_Indx, _Tp>(_VSTD::forward::type>::type>(_VSTD::get<_Indx>(__t)))... + {} + + template >::value + >::type + > + _LIBCPP_INLINE_VISIBILITY + __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, + _VSTD::forward::type>::type>(_VSTD::get<_Indx>(__t)))... + {} + + template + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __tuple_assignable<_Tuple, tuple<_Tp...> >::value, + __tuple_impl& + >::type + operator=(_Tuple&& __t) _NOEXCEPT_((__all::type>::type>::value...>::value)) + { + __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward::type>::type>(_VSTD::get<_Indx>(__t)))...); + return *this; + } + + __tuple_impl(const __tuple_impl&) = default; + __tuple_impl(__tuple_impl&&) = default; + + _LIBCPP_INLINE_VISIBILITY + __tuple_impl& + operator=(const __tuple_impl& __t) _NOEXCEPT_((__all::value...>::value)) + { + __swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast&>(__t).get())...); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __tuple_impl& + operator=(__tuple_impl&& __t) _NOEXCEPT_((__all::value...>::value)) + { + __swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + void swap(__tuple_impl& __t) + _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) + { + __swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...); + } +}; + +template +struct __tuple_like_with_size_imp : false_type {}; + +template +struct __tuple_like_with_size_imp + : integral_constant {}; + +template ::type> +using __tuple_like_with_size = __tuple_like_with_size_imp< + __tuple_like<_RawTuple>::value, + tuple_size<_RawTuple>, _ExpectedSize + >; + + +struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail { + template + static constexpr bool __enable_explicit() { return false; } + template + static constexpr bool __enable_implicit() { return false; } +}; + +template +class _LIBCPP_TYPE_VIS_ONLY tuple +{ + typedef __tuple_impl::type, _Tp...> base; + + base base_; + + template + struct _PackExpandsToThisTuple : false_type {}; + + template + struct _PackExpandsToThisTuple<_Arg> + : is_same::type, tuple> {}; + + template + struct _CheckArgsConstructor : __check_tuple_constructor_fail {}; + + template + struct _CheckArgsConstructor + { + template + static constexpr bool __enable_explicit() { + return + __tuple_constructible< + tuple<_Args...>, + typename __make_tuple_types::type + >::value && + !__tuple_convertible< + tuple<_Args...>, + typename __make_tuple_types::type + >::value && + __all_default_constructible< + typename __make_tuple_types::type + >::value; + } + + template + static constexpr bool __enable_implicit() { + return + __tuple_convertible< + tuple<_Args...>, + typename __make_tuple_types::type + >::value && + __all_default_constructible< + typename __make_tuple_types::type + >::value; + } + }; + + template + struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {}; + + template + struct _CheckTupleLikeConstructor + { + template + static constexpr bool __enable_implicit() { + return __tuple_convertible<_Tuple, tuple>::value; + } + + template + static constexpr bool __enable_explicit() { + return __tuple_constructible<_Tuple, tuple>::value + && !__tuple_convertible<_Tuple, tuple>::value; + } + }; + + template + struct _CheckTupleLikeConstructor + { + // This trait is used to disable the tuple-like constructor when + // the UTypes... constructor should be selected instead. + // See LWG issue #2549. + template + using _PreferTupleLikeConstructor = __lazy_or< + // Don't attempt the two checks below if the tuple we are given + // has the same type as this tuple. + is_same::type, tuple>, + __lazy_and< + __lazy_not>, + __lazy_not> + > + >; + + template + static constexpr bool __enable_implicit() { + return __lazy_and< + __tuple_convertible<_Tuple, tuple>, + _PreferTupleLikeConstructor<_Tuple> + >::value; + } + + template + static constexpr bool __enable_explicit() { + return __lazy_and< + __tuple_constructible<_Tuple, tuple>, + _PreferTupleLikeConstructor<_Tuple>, + __lazy_not<__tuple_convertible<_Tuple, tuple>> + >::value; + } + }; + + template friend _LIBCPP_CONSTEXPR_AFTER_CXX11 + typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT; + template friend _LIBCPP_CONSTEXPR_AFTER_CXX11 + const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT; + template friend _LIBCPP_CONSTEXPR_AFTER_CXX11 + typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT; + template friend _LIBCPP_CONSTEXPR_AFTER_CXX11 + const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT; +public: + + template , _Dummy>::value...>::value + >::type> + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR tuple() + _NOEXCEPT_(__all::value...>::value) {} + + template , + __lazy_all<__dependent_type, _Dummy>...> + >::value + >::type> + _LIBCPP_INLINE_VISIBILITY + tuple(_AllocArgT, _Alloc const& __a) + : base_(allocator_arg_t(), __a, + __tuple_indices<>(), __tuple_types<>(), + typename __make_tuple_indices::type(), + __tuple_types<_Tp...>()) {} + + template ::template __enable_implicit<_Tp...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + tuple(const _Tp& ... __t) _NOEXCEPT_((__all::value...>::value)) + : base_(typename __make_tuple_indices::type(), + typename __make_tuple_types::type(), + typename __make_tuple_indices<0>::type(), + typename __make_tuple_types::type(), + __t... + ) {} + + template ::template __enable_explicit<_Tp...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all::value...>::value)) + : base_(typename __make_tuple_indices::type(), + typename __make_tuple_types::type(), + typename __make_tuple_indices<0>::type(), + typename __make_tuple_types::type(), + __t... + ) {} + + template ::template __enable_implicit<_Tp...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY + tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t) + : base_(allocator_arg_t(), __a, + typename __make_tuple_indices::type(), + typename __make_tuple_types::type(), + typename __make_tuple_indices<0>::type(), + typename __make_tuple_types::type(), + __t... + ) {} + + template ::template __enable_explicit<_Tp...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY + explicit + tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t) + : base_(allocator_arg_t(), __a, + typename __make_tuple_indices::type(), + typename __make_tuple_types::type(), + typename __make_tuple_indices<0>::type(), + typename __make_tuple_types::type(), + __t... + ) {} + + template ::value + >::template __enable_implicit<_Up...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + tuple(_Up&&... __u) + _NOEXCEPT_(( + is_nothrow_constructible::type, + typename __make_tuple_types::type, + typename __make_tuple_indices::type, + typename __make_tuple_types::type, + _Up... + >::value + )) + : base_(typename __make_tuple_indices::type(), + typename __make_tuple_types::type(), + typename __make_tuple_indices::type(), + typename __make_tuple_types::type(), + _VSTD::forward<_Up>(__u)...) {} + + template ::value + >::template __enable_explicit<_Up...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit + tuple(_Up&&... __u) + _NOEXCEPT_(( + is_nothrow_constructible::type, + typename __make_tuple_types::type, + typename __make_tuple_indices::type, + typename __make_tuple_types::type, + _Up... + >::value + )) + : base_(typename __make_tuple_indices::type(), + typename __make_tuple_types::type(), + typename __make_tuple_indices::type(), + typename __make_tuple_types::type(), + _VSTD::forward<_Up>(__u)...) {} + + template ::value + >::template __enable_implicit<_Up...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY + tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) + : base_(allocator_arg_t(), __a, + typename __make_tuple_indices::type(), + typename __make_tuple_types::type(), + typename __make_tuple_indices::type(), + typename __make_tuple_types::type(), + _VSTD::forward<_Up>(__u)...) {} + + template ::value + >::template __enable_explicit<_Up...>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY + explicit + tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) + : base_(allocator_arg_t(), __a, + typename __make_tuple_indices::type(), + typename __make_tuple_types::type(), + typename __make_tuple_indices::type(), + typename __make_tuple_types::type(), + _VSTD::forward<_Up>(__u)...) {} + + template ::value + && !_PackExpandsToThisTuple<_Tuple>::value + >::template __enable_implicit<_Tuple>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible::value)) + : base_(_VSTD::forward<_Tuple>(__t)) {} + + template ::value + && !_PackExpandsToThisTuple<_Tuple>::value + >::template __enable_explicit<_Tuple>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + explicit + tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible::value)) + : base_(_VSTD::forward<_Tuple>(__t)) {} + + template ::value + >::template __enable_implicit<_Tuple>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY + tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) + : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {} + + template ::value + >::template __enable_explicit<_Tuple>(), + bool + >::type = false + > + _LIBCPP_INLINE_VISIBILITY + explicit + tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) + : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {} + + template ::value + >::type + > + _LIBCPP_INLINE_VISIBILITY + tuple& + operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable::value)) + { + base_.operator=(_VSTD::forward<_Tuple>(__t)); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) + {base_.swap(__t.base_);} +}; + +template <> +class _LIBCPP_TYPE_VIS_ONLY tuple<> +{ +public: + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR tuple() _NOEXCEPT {} + template + _LIBCPP_INLINE_VISIBILITY + tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {} + template + _LIBCPP_INLINE_VISIBILITY + tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {} + template + _LIBCPP_INLINE_VISIBILITY + tuple(array<_Up, 0>) _NOEXCEPT {} + template + _LIBCPP_INLINE_VISIBILITY + tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {} + _LIBCPP_INLINE_VISIBILITY + void swap(tuple&) _NOEXCEPT {} +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __all<__is_swappable<_Tp>::value...>::value, + void +>::type +swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) + _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) + {__t.swap(__u);} + +// get + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(tuple<_Tp...>& __t) _NOEXCEPT +{ + typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; + return static_cast<__tuple_leaf<_Ip, type>&>(__t.base_).get(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(const tuple<_Tp...>& __t) _NOEXCEPT +{ + typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; + return static_cast&>(__t.base_).get(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(tuple<_Tp...>&& __t) _NOEXCEPT +{ + typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; + return static_cast( + static_cast<__tuple_leaf<_Ip, type>&&>(__t.base_).get()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(const tuple<_Tp...>&& __t) _NOEXCEPT +{ + typedef typename tuple_element<_Ip, tuple<_Tp...> >::type type; + return static_cast( + static_cast&&>(__t.base_).get()); +} + +#if _LIBCPP_STD_VER > 11 + +namespace __find_detail { + +static constexpr size_t __not_found = -1; +static constexpr size_t __ambiguous = __not_found - 1; + +inline _LIBCPP_INLINE_VISIBILITY +constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) { + return !__matches ? __res : + (__res == __not_found ? __curr_i : __ambiguous); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) { + return __i == _Nx ? __not_found : + __find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]); +} + +template +struct __find_exactly_one_checked { + static constexpr bool __matches[] = {is_same<_T1, _Args>::value...}; + static constexpr size_t value = __find_detail::__find_idx(0, __matches); + static_assert (value != __not_found, "type not found in type list" ); + static_assert(value != __ambiguous,"type occurs more than once in type list"); +}; + +template +struct __find_exactly_one_checked<_T1> { + static_assert(!is_same<_T1, _T1>::value, "type not in empty type list"); +}; + +} // namespace __find_detail; + +template +struct __find_exactly_one_t + : public __find_detail::__find_exactly_one_checked<_T1, _Args...> { +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1& get(tuple<_Args...>& __tup) noexcept +{ + return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept +{ + return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept +{ + return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup)); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept +{ + return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup)); +} + +#endif + +// tie + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +tuple<_Tp&...> +tie(_Tp&... __t) _NOEXCEPT +{ + return tuple<_Tp&...>(__t...); +} + +template +struct __ignore_t +{ + template + _LIBCPP_INLINE_VISIBILITY + const __ignore_t& operator=(_Tp&&) const {return *this;} +}; + +namespace { const __ignore_t ignore = __ignore_t(); } + +template +struct __make_tuple_return_impl +{ + typedef _Tp type; +}; + +template +struct __make_tuple_return_impl > +{ + typedef _Tp& type; +}; + +template +struct __make_tuple_return +{ + typedef typename __make_tuple_return_impl::type>::type type; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +tuple::type...> +make_tuple(_Tp&&... __t) +{ + return tuple::type...>(_VSTD::forward<_Tp>(__t)...); +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +tuple<_Tp&&...> +forward_as_tuple(_Tp&&... __t) _NOEXCEPT +{ + return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...); +} + +template +struct __tuple_equal +{ + template + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _Tp& __x, const _Up& __y) + { + return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y); + } +}; + +template <> +struct __tuple_equal<0> +{ + template + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _Tp&, const _Up&) + { + return true; + } +}; + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ + return __tuple_equal()(__x, __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ + return !(__x == __y); +} + +template +struct __tuple_less +{ + template + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _Tp& __x, const _Up& __y) + { + const size_t __idx = tuple_size<_Tp>::value - _Ip; + if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y)) + return true; + if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x)) + return false; + return __tuple_less<_Ip-1>()(__x, __y); + } +}; + +template <> +struct __tuple_less<0> +{ + template + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + bool operator()(const _Tp&, const _Up&) + { + return false; + } +}; + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ + return __tuple_less()(__x, __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ + return __y < __x; +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ + return !(__x < __y); +} + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +bool +operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) +{ + return !(__y < __x); +} + +// tuple_cat + +template struct __tuple_cat_type; + +template +struct __tuple_cat_type, __tuple_types<_Utypes...> > +{ + typedef tuple<_Ttypes..., _Utypes...> type; +}; + +template +struct __tuple_cat_return_1 +{ +}; + +template +struct __tuple_cat_return_1, true, _Tuple0> +{ + typedef typename __tuple_cat_type, + typename __make_tuple_types::type>::type>::type + type; +}; + +template +struct __tuple_cat_return_1, true, _Tuple0, _Tuple1, _Tuples...> + : public __tuple_cat_return_1< + typename __tuple_cat_type< + tuple<_Types...>, + typename __make_tuple_types::type>::type + >::type, + __tuple_like::type>::value, + _Tuple1, _Tuples...> +{ +}; + +template struct __tuple_cat_return; + +template +struct __tuple_cat_return<_Tuple0, _Tuples...> + : public __tuple_cat_return_1, + __tuple_like::type>::value, _Tuple0, + _Tuples...> +{ +}; + +template <> +struct __tuple_cat_return<> +{ + typedef tuple<> type; +}; + +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +tuple<> +tuple_cat() +{ + return tuple<>(); +} + +template +struct __tuple_cat_return_ref_imp; + +template +struct __tuple_cat_return_ref_imp, __tuple_indices<_I0...>, _Tuple0> +{ + typedef typename remove_reference<_Tuple0>::type _T0; + typedef tuple<_Types..., typename __apply_cv<_Tuple0, + typename tuple_element<_I0, _T0>::type>::type&&...> type; +}; + +template +struct __tuple_cat_return_ref_imp, __tuple_indices<_I0...>, + _Tuple0, _Tuple1, _Tuples...> + : public __tuple_cat_return_ref_imp< + tuple<_Types..., typename __apply_cv<_Tuple0, + typename tuple_element<_I0, + typename remove_reference<_Tuple0>::type>::type>::type&&...>, + typename __make_tuple_indices::type>::value>::type, + _Tuple1, _Tuples...> +{ +}; + +template +struct __tuple_cat_return_ref + : public __tuple_cat_return_ref_imp, + typename __make_tuple_indices< + tuple_size::type>::value + >::type, _Tuple0, _Tuples...> +{ +}; + +template +struct __tuple_cat; + +template +struct __tuple_cat, __tuple_indices<_I0...>, __tuple_indices<_J0...> > +{ + template + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + typename __tuple_cat_return_ref&&, _Tuple0&&>::type + operator()(tuple<_Types...> __t, _Tuple0&& __t0) + { + return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))..., + _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...); + } + + template + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 + typename __tuple_cat_return_ref&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type + operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls) + { + typedef typename remove_reference<_Tuple0>::type _T0; + typedef typename remove_reference<_Tuple1>::type _T1; + return __tuple_cat< + tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>, + typename __make_tuple_indices::value>::type, + typename __make_tuple_indices::value>::type>() + (forward_as_tuple( + _VSTD::forward<_Types>(_VSTD::get<_I0>(__t))..., + _VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))... + ), + _VSTD::forward<_Tuple1>(__t1), + _VSTD::forward<_Tuples>(__tpls)...); + } +}; + +template +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +typename __tuple_cat_return<_Tuple0, _Tuples...>::type +tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) +{ + typedef typename remove_reference<_Tuple0>::type _T0; + return __tuple_cat, __tuple_indices<>, + typename __make_tuple_indices::value>::type>() + (tuple<>(), _VSTD::forward<_Tuple0>(__t0), + _VSTD::forward<_Tuples>(__tpls)...); +} + +template +struct _LIBCPP_TYPE_VIS_ONLY uses_allocator, _Alloc> + : true_type {}; + +template +template +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(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...), + second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...) +{ +} + +#endif // _LIBCPP_HAS_NO_VARIADICS + +#if _LIBCPP_STD_VER > 14 +template +constexpr size_t tuple_size_v = tuple_size<_Tp>::value; + +#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; } + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t, + __tuple_indices<_Id...>) +_LIBCPP_NOEXCEPT_RETURN( + _VSTD::__invoke_constexpr( + _VSTD::forward<_Fn>(__f), + _VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...) +) + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t) +_LIBCPP_NOEXCEPT_RETURN( + _VSTD::__apply_tuple_impl( + _VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t), + typename __make_tuple_indices>>::type{}) +) + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>) +_LIBCPP_NOEXCEPT_RETURN( + _Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...) +) + +template +inline _LIBCPP_INLINE_VISIBILITY +constexpr _Tp make_from_tuple(_Tuple&& __t) +_LIBCPP_NOEXCEPT_RETURN( + _VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t), + typename __make_tuple_indices>>::type{}) +) + +#undef _LIBCPP_NOEXCEPT_RETURN + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_TUPLE -- cgit v1.2.3-59-g8ed1b