10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_TUPLE 110b57cec5SDimitry Andric#define _LIBCPP_TUPLE 120b57cec5SDimitry Andric 13*5f757f3fSDimitry Andric// clang-format off 14*5f757f3fSDimitry Andric 150b57cec5SDimitry Andric/* 160b57cec5SDimitry Andric tuple synopsis 170b57cec5SDimitry Andric 180b57cec5SDimitry Andricnamespace std 190b57cec5SDimitry Andric{ 200b57cec5SDimitry Andric 210b57cec5SDimitry Andrictemplate <class... T> 220b57cec5SDimitry Andricclass tuple { 230b57cec5SDimitry Andricpublic: 24e40139ffSDimitry Andric explicit(see-below) constexpr tuple(); 25e40139ffSDimitry Andric explicit(see-below) tuple(const T&...); // constexpr in C++14 260b57cec5SDimitry Andric template <class... U> 27e40139ffSDimitry Andric explicit(see-below) tuple(U&&...); // constexpr in C++14 280b57cec5SDimitry Andric tuple(const tuple&) = default; 290b57cec5SDimitry Andric tuple(tuple&&) = default; 3081ad6265SDimitry Andric 3181ad6265SDimitry Andric template<class... UTypes> 3281ad6265SDimitry Andric constexpr explicit(see-below) tuple(tuple<UTypes...>&); // C++23 330b57cec5SDimitry Andric template <class... U> 34e40139ffSDimitry Andric explicit(see-below) tuple(const tuple<U...>&); // constexpr in C++14 350b57cec5SDimitry Andric template <class... U> 36e40139ffSDimitry Andric explicit(see-below) tuple(tuple<U...>&&); // constexpr in C++14 3781ad6265SDimitry Andric template<class... UTypes> 3881ad6265SDimitry Andric constexpr explicit(see-below) tuple(const tuple<UTypes...>&&); // C++23 3981ad6265SDimitry Andric 4081ad6265SDimitry Andric template<class U1, class U2> 4181ad6265SDimitry Andric constexpr explicit(see-below) tuple(pair<U1, U2>&); // iff sizeof...(Types) == 2 // C++23 420b57cec5SDimitry Andric template <class U1, class U2> 43e40139ffSDimitry Andric explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14 440b57cec5SDimitry Andric template <class U1, class U2> 45e40139ffSDimitry Andric explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14 4681ad6265SDimitry Andric template<class U1, class U2> 4781ad6265SDimitry Andric constexpr explicit(see-below) tuple(const pair<U1, U2>&&); // iff sizeof...(Types) == 2 // C++23 480b57cec5SDimitry Andric 490b57cec5SDimitry Andric // allocator-extended constructors 500b57cec5SDimitry Andric template <class Alloc> 510b57cec5SDimitry Andric tuple(allocator_arg_t, const Alloc& a); 520b57cec5SDimitry Andric template <class Alloc> 53fe6060f1SDimitry Andric explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...); // constexpr in C++20 540b57cec5SDimitry Andric template <class Alloc, class... U> 55fe6060f1SDimitry Andric explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...); // constexpr in C++20 560b57cec5SDimitry Andric template <class Alloc> 57fe6060f1SDimitry Andric tuple(allocator_arg_t, const Alloc& a, const tuple&); // constexpr in C++20 580b57cec5SDimitry Andric template <class Alloc> 59fe6060f1SDimitry Andric tuple(allocator_arg_t, const Alloc& a, tuple&&); // constexpr in C++20 6081ad6265SDimitry Andric template<class Alloc, class... UTypes> 6181ad6265SDimitry Andric constexpr explicit(see-below) 6281ad6265SDimitry Andric tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&); // C++23 630b57cec5SDimitry Andric template <class Alloc, class... U> 64fe6060f1SDimitry Andric explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&); // constexpr in C++20 650b57cec5SDimitry Andric template <class Alloc, class... U> 66fe6060f1SDimitry Andric explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&); // constexpr in C++20 6781ad6265SDimitry Andric template<class Alloc, class... UTypes> 6881ad6265SDimitry Andric constexpr explicit(see-below) 6981ad6265SDimitry Andric tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&&); // C++23 7081ad6265SDimitry Andric template<class Alloc, class U1, class U2> 7181ad6265SDimitry Andric constexpr explicit(see-below) 7281ad6265SDimitry Andric tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&); // C++23 730b57cec5SDimitry Andric template <class Alloc, class U1, class U2> 74fe6060f1SDimitry Andric explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); // constexpr in C++20 750b57cec5SDimitry Andric template <class Alloc, class U1, class U2> 76fe6060f1SDimitry Andric explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&); // constexpr in C++20 7781ad6265SDimitry Andric template<class Alloc, class U1, class U2> 7881ad6265SDimitry Andric constexpr explicit(see-below) 7981ad6265SDimitry Andric tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&&); // C++23 800b57cec5SDimitry Andric 81fe6060f1SDimitry Andric tuple& operator=(const tuple&); // constexpr in C++20 8281ad6265SDimitry Andric constexpr const tuple& operator=(const tuple&) const; // C++23 83fe6060f1SDimitry Andric tuple& operator=(tuple&&) noexcept(is_nothrow_move_assignable_v<T> && ...); // constexpr in C++20 8481ad6265SDimitry Andric constexpr const tuple& operator=(tuple&&) const; // C++23 850b57cec5SDimitry Andric template <class... U> 86fe6060f1SDimitry Andric tuple& operator=(const tuple<U...>&); // constexpr in C++20 8781ad6265SDimitry Andric template<class... UTypes> 8881ad6265SDimitry Andric constexpr const tuple& operator=(const tuple<UTypes...>&) const; // C++23 890b57cec5SDimitry Andric template <class... U> 90fe6060f1SDimitry Andric tuple& operator=(tuple<U...>&&); // constexpr in C++20 9181ad6265SDimitry Andric template<class... UTypes> 9281ad6265SDimitry Andric constexpr const tuple& operator=(tuple<UTypes...>&&) const; // C++23 930b57cec5SDimitry Andric template <class U1, class U2> 94fe6060f1SDimitry Andric tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++20 950b57cec5SDimitry Andric template<class U1, class U2> 9681ad6265SDimitry Andric constexpr const tuple& operator=(const pair<U1, U2>&) const; // iff sizeof...(Types) == 2 // C++23 9781ad6265SDimitry Andric template <class U1, class U2> 98fe6060f1SDimitry Andric tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++20 9981ad6265SDimitry Andric template<class U1, class U2> 10081ad6265SDimitry Andric constexpr const tuple& operator=(pair<U1, U2>&&) const; // iff sizeof...(Types) == 2 // C++23 1010b57cec5SDimitry Andric 102fe6060f1SDimitry Andric template<class U, size_t N> 103fe6060f1SDimitry Andric tuple& operator=(array<U, N> const&) // iff sizeof...(T) == N, EXTENSION 104fe6060f1SDimitry Andric template<class U, size_t N> 105fe6060f1SDimitry Andric tuple& operator=(array<U, N>&&) // iff sizeof...(T) == N, EXTENSION 106fe6060f1SDimitry Andric 107fe6060f1SDimitry Andric void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...)); // constexpr in C++20 10881ad6265SDimitry Andric constexpr void swap(const tuple&) const noexcept(see-below); // C++23 1090b57cec5SDimitry Andric}; 1100b57cec5SDimitry Andric 11104eeddc0SDimitry Andric 11204eeddc0SDimitry Andrictemplate<class... TTypes, class... UTypes, template<class> class TQual, template<class> class UQual> // since C++23 11304eeddc0SDimitry Andric requires requires { typename tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>; } 11404eeddc0SDimitry Andricstruct basic_common_reference<tuple<TTypes...>, tuple<UTypes...>, TQual, UQual> { 11504eeddc0SDimitry Andric using type = tuple<common_reference_t<TQual<TTypes>, UQual<UTypes>>...>; 11604eeddc0SDimitry Andric}; 11704eeddc0SDimitry Andric 11804eeddc0SDimitry Andrictemplate<class... TTypes, class... UTypes> // since C++23 11904eeddc0SDimitry Andric requires requires { typename tuple<common_type_t<TTypes, UTypes>...>; } 12004eeddc0SDimitry Andricstruct common_type<tuple<TTypes...>, tuple<UTypes...>> { 12104eeddc0SDimitry Andric using type = tuple<common_type_t<TTypes, UTypes>...>; 12204eeddc0SDimitry Andric}; 12304eeddc0SDimitry Andric 124e40139ffSDimitry Andrictemplate <class ...T> 125e40139ffSDimitry Andrictuple(T...) -> tuple<T...>; // since C++17 126e40139ffSDimitry Andrictemplate <class T1, class T2> 127e40139ffSDimitry Andrictuple(pair<T1, T2>) -> tuple<T1, T2>; // since C++17 128e40139ffSDimitry Andrictemplate <class Alloc, class ...T> 129e40139ffSDimitry Andrictuple(allocator_arg_t, Alloc, T...) -> tuple<T...>; // since C++17 130e40139ffSDimitry Andrictemplate <class Alloc, class T1, class T2> 131e40139ffSDimitry Andrictuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++17 132e40139ffSDimitry Andrictemplate <class Alloc, class ...T> 133e40139ffSDimitry Andrictuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17 134e40139ffSDimitry Andric 1350b57cec5SDimitry Andricinline constexpr unspecified ignore; 1360b57cec5SDimitry Andric 1370b57cec5SDimitry Andrictemplate <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14 1380b57cec5SDimitry Andrictemplate <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14 1390b57cec5SDimitry Andrictemplate <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14 1400b57cec5SDimitry Andrictemplate <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14 1410b57cec5SDimitry Andric 1420b57cec5SDimitry Andric// [tuple.apply], calling a function with a tuple of arguments: 1430b57cec5SDimitry Andrictemplate <class F, class Tuple> 1440b57cec5SDimitry Andric constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17 1450b57cec5SDimitry Andrictemplate <class T, class Tuple> 1460b57cec5SDimitry Andric constexpr T make_from_tuple(Tuple&& t); // C++17 1470b57cec5SDimitry Andric 1480b57cec5SDimitry Andric// 20.4.1.4, tuple helper classes: 1490b57cec5SDimitry Andrictemplate <class T> struct tuple_size; // undefined 1500b57cec5SDimitry Andrictemplate <class... T> struct tuple_size<tuple<T...>>; 1510b57cec5SDimitry Andrictemplate <class T> 1520b57cec5SDimitry Andric inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17 1530b57cec5SDimitry Andrictemplate <size_t I, class T> struct tuple_element; // undefined 1540b57cec5SDimitry Andrictemplate <size_t I, class... T> struct tuple_element<I, tuple<T...>>; 1550b57cec5SDimitry Andrictemplate <size_t I, class T> 1560b57cec5SDimitry Andric using tuple_element_t = typename tuple_element <I, T>::type; // C++14 1570b57cec5SDimitry Andric 1580b57cec5SDimitry Andric// 20.4.1.5, element access: 1590b57cec5SDimitry Andrictemplate <size_t I, class... T> 1600b57cec5SDimitry Andric typename tuple_element<I, tuple<T...>>::type& 1610b57cec5SDimitry Andric get(tuple<T...>&) noexcept; // constexpr in C++14 1620b57cec5SDimitry Andrictemplate <size_t I, class... T> 1630b57cec5SDimitry Andric const typename tuple_element<I, tuple<T...>>::type& 1640b57cec5SDimitry Andric get(const tuple<T...>&) noexcept; // constexpr in C++14 1650b57cec5SDimitry Andrictemplate <size_t I, class... T> 1660b57cec5SDimitry Andric typename tuple_element<I, tuple<T...>>::type&& 1670b57cec5SDimitry Andric get(tuple<T...>&&) noexcept; // constexpr in C++14 1680b57cec5SDimitry Andrictemplate <size_t I, class... T> 1690b57cec5SDimitry Andric const typename tuple_element<I, tuple<T...>>::type&& 1700b57cec5SDimitry Andric get(const tuple<T...>&&) noexcept; // constexpr in C++14 1710b57cec5SDimitry Andric 1720b57cec5SDimitry Andrictemplate <class T1, class... T> 1730b57cec5SDimitry Andric constexpr T1& get(tuple<T...>&) noexcept; // C++14 1740b57cec5SDimitry Andrictemplate <class T1, class... T> 1750b57cec5SDimitry Andric constexpr const T1& get(const tuple<T...>&) noexcept; // C++14 1760b57cec5SDimitry Andrictemplate <class T1, class... T> 1770b57cec5SDimitry Andric constexpr T1&& get(tuple<T...>&&) noexcept; // C++14 1780b57cec5SDimitry Andrictemplate <class T1, class... T> 1790b57cec5SDimitry Andric constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14 1800b57cec5SDimitry Andric 1810b57cec5SDimitry Andric// 20.4.1.6, relational operators: 1820b57cec5SDimitry Andrictemplate<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 183349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20 184349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20 185349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20 186349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20 187349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20 188349cc55cSDimitry Andrictemplate<class... T, class... U> 189349cc55cSDimitry Andric constexpr common_comparison_category_t<synth-three-way-result<T, U>...> 190349cc55cSDimitry Andric operator<=>(const tuple<T...>&, const tuple<U...>&); // since C++20 1910b57cec5SDimitry Andric 1920b57cec5SDimitry Andrictemplate <class... Types, class Alloc> 1930b57cec5SDimitry Andric struct uses_allocator<tuple<Types...>, Alloc>; 1940b57cec5SDimitry Andric 1950b57cec5SDimitry Andrictemplate <class... Types> 1960b57cec5SDimitry Andric void 1970b57cec5SDimitry Andric swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y))); 1980b57cec5SDimitry Andric 19981ad6265SDimitry Andrictemplate <class... Types> 20081ad6265SDimitry Andric constexpr void swap(const tuple<Types...>& x, const tuple<Types...>& y) noexcept(see-below); // C++23 20181ad6265SDimitry Andric 2020b57cec5SDimitry Andric} // std 2030b57cec5SDimitry Andric 2040b57cec5SDimitry Andric*/ 2050b57cec5SDimitry Andric 206*5f757f3fSDimitry Andric// clang-format on 207*5f757f3fSDimitry Andric 20881ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 209349cc55cSDimitry Andric#include <__compare/common_comparison_category.h> 210349cc55cSDimitry Andric#include <__compare/synth_three_way.h> 2110b57cec5SDimitry Andric#include <__config> 212bdd1243dSDimitry Andric#include <__functional/invoke.h> 213bdd1243dSDimitry Andric#include <__fwd/array.h> 21406c3fb27SDimitry Andric#include <__fwd/get.h> 21506c3fb27SDimitry Andric#include <__fwd/tuple.h> 216fe6060f1SDimitry Andric#include <__memory/allocator_arg_t.h> 217fe6060f1SDimitry Andric#include <__memory/uses_allocator.h> 21806c3fb27SDimitry Andric#include <__tuple/make_tuple_types.h> 21906c3fb27SDimitry Andric#include <__tuple/sfinae_helpers.h> 22006c3fb27SDimitry Andric#include <__tuple/tuple_element.h> 22106c3fb27SDimitry Andric#include <__tuple/tuple_indices.h> 22206c3fb27SDimitry Andric#include <__tuple/tuple_like_ext.h> 22306c3fb27SDimitry Andric#include <__tuple/tuple_size.h> 22406c3fb27SDimitry Andric#include <__tuple/tuple_types.h> 225bdd1243dSDimitry Andric#include <__type_traits/apply_cv.h> 226bdd1243dSDimitry Andric#include <__type_traits/common_reference.h> 227bdd1243dSDimitry Andric#include <__type_traits/common_type.h> 228bdd1243dSDimitry Andric#include <__type_traits/conditional.h> 229bdd1243dSDimitry Andric#include <__type_traits/conjunction.h> 230bdd1243dSDimitry Andric#include <__type_traits/copy_cvref.h> 231bdd1243dSDimitry Andric#include <__type_traits/disjunction.h> 232bdd1243dSDimitry Andric#include <__type_traits/is_arithmetic.h> 233bdd1243dSDimitry Andric#include <__type_traits/is_assignable.h> 234bdd1243dSDimitry Andric#include <__type_traits/is_constructible.h> 235bdd1243dSDimitry Andric#include <__type_traits/is_convertible.h> 236bdd1243dSDimitry Andric#include <__type_traits/is_copy_assignable.h> 237bdd1243dSDimitry Andric#include <__type_traits/is_copy_constructible.h> 238bdd1243dSDimitry Andric#include <__type_traits/is_default_constructible.h> 239bdd1243dSDimitry Andric#include <__type_traits/is_empty.h> 240bdd1243dSDimitry Andric#include <__type_traits/is_final.h> 241bdd1243dSDimitry Andric#include <__type_traits/is_implicitly_default_constructible.h> 242bdd1243dSDimitry Andric#include <__type_traits/is_move_assignable.h> 243bdd1243dSDimitry Andric#include <__type_traits/is_move_constructible.h> 244bdd1243dSDimitry Andric#include <__type_traits/is_nothrow_assignable.h> 245bdd1243dSDimitry Andric#include <__type_traits/is_nothrow_constructible.h> 246bdd1243dSDimitry Andric#include <__type_traits/is_nothrow_copy_assignable.h> 247bdd1243dSDimitry Andric#include <__type_traits/is_nothrow_copy_constructible.h> 248bdd1243dSDimitry Andric#include <__type_traits/is_nothrow_default_constructible.h> 249bdd1243dSDimitry Andric#include <__type_traits/is_nothrow_move_assignable.h> 250bdd1243dSDimitry Andric#include <__type_traits/is_reference.h> 251bdd1243dSDimitry Andric#include <__type_traits/is_same.h> 252bdd1243dSDimitry Andric#include <__type_traits/is_swappable.h> 253bdd1243dSDimitry Andric#include <__type_traits/lazy.h> 254bdd1243dSDimitry Andric#include <__type_traits/maybe_const.h> 255bdd1243dSDimitry Andric#include <__type_traits/nat.h> 256bdd1243dSDimitry Andric#include <__type_traits/negation.h> 257bdd1243dSDimitry Andric#include <__type_traits/remove_cvref.h> 258bdd1243dSDimitry Andric#include <__type_traits/remove_reference.h> 25906c3fb27SDimitry Andric#include <__type_traits/unwrap_ref.h> 260fe6060f1SDimitry Andric#include <__utility/forward.h> 261349cc55cSDimitry Andric#include <__utility/integer_sequence.h> 262fe6060f1SDimitry Andric#include <__utility/move.h> 26381ad6265SDimitry Andric#include <__utility/pair.h> 26481ad6265SDimitry Andric#include <__utility/piecewise_construct.h> 26581ad6265SDimitry Andric#include <__utility/swap.h> 2660b57cec5SDimitry Andric#include <cstddef> 2670b57cec5SDimitry Andric#include <version> 2680b57cec5SDimitry Andric 26981ad6265SDimitry Andric// standard-mandated includes 270bdd1243dSDimitry Andric 271bdd1243dSDimitry Andric// [tuple.syn] 27281ad6265SDimitry Andric#include <compare> 27381ad6265SDimitry Andric 2740b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2750b57cec5SDimitry Andric# pragma GCC system_header 2760b57cec5SDimitry Andric#endif 2770b57cec5SDimitry Andric 27806c3fb27SDimitry Andric_LIBCPP_PUSH_MACROS 27906c3fb27SDimitry Andric#include <__undef_macros> 28006c3fb27SDimitry Andric 2810b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 2820b57cec5SDimitry Andric 2830b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2840b57cec5SDimitry Andric 2850b57cec5SDimitry Andric 2860b57cec5SDimitry Andric// __tuple_leaf 2870b57cec5SDimitry Andric 2880b57cec5SDimitry Andrictemplate <size_t _Ip, class _Hp, 2890b57cec5SDimitry Andric bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value 2900b57cec5SDimitry Andric > 2910b57cec5SDimitry Andricclass __tuple_leaf; 2920b57cec5SDimitry Andric 2930b57cec5SDimitry Andrictemplate <size_t _Ip, class _Hp, bool _Ep> 294*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 2950b57cec5SDimitry Andricvoid swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y) 2960b57cec5SDimitry Andric _NOEXCEPT_(__is_nothrow_swappable<_Hp>::value) 2970b57cec5SDimitry Andric{ 2980b57cec5SDimitry Andric swap(__x.get(), __y.get()); 2990b57cec5SDimitry Andric} 3000b57cec5SDimitry Andric 30181ad6265SDimitry Andrictemplate <size_t _Ip, class _Hp, bool _Ep> 302bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 30381ad6265SDimitry Andricvoid swap(const __tuple_leaf<_Ip, _Hp, _Ep>& __x, const __tuple_leaf<_Ip, _Hp, _Ep>& __y) 30481ad6265SDimitry Andric _NOEXCEPT_(__is_nothrow_swappable<const _Hp>::value) { 30581ad6265SDimitry Andric swap(__x.get(), __y.get()); 30681ad6265SDimitry Andric} 30781ad6265SDimitry Andric 3080b57cec5SDimitry Andrictemplate <size_t _Ip, class _Hp, bool> 3090b57cec5SDimitry Andricclass __tuple_leaf 3100b57cec5SDimitry Andric{ 3110b57cec5SDimitry Andric _Hp __value_; 3120b57cec5SDimitry Andric 3130b57cec5SDimitry Andric template <class _Tp> 31406c3fb27SDimitry Andric static _LIBCPP_HIDE_FROM_ABI constexpr bool __can_bind_reference() { 3150b57cec5SDimitry Andric#if __has_keyword(__reference_binds_to_temporary) 3160b57cec5SDimitry Andric return !__reference_binds_to_temporary(_Hp, _Tp); 3170b57cec5SDimitry Andric#else 3180b57cec5SDimitry Andric return true; 3190b57cec5SDimitry Andric#endif 3200b57cec5SDimitry Andric } 3210b57cec5SDimitry Andric 322bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 3230b57cec5SDimitry Andric __tuple_leaf& operator=(const __tuple_leaf&); 3240b57cec5SDimitry Andricpublic: 325*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf() 3260b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_() 3270b57cec5SDimitry Andric {static_assert(!is_reference<_Hp>::value, 3280b57cec5SDimitry Andric "Attempted to default construct a reference element in a tuple");} 3290b57cec5SDimitry Andric 3300b57cec5SDimitry Andric template <class _Alloc> 331*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 3320b57cec5SDimitry Andric __tuple_leaf(integral_constant<int, 0>, const _Alloc&) 3330b57cec5SDimitry Andric : __value_() 3340b57cec5SDimitry Andric {static_assert(!is_reference<_Hp>::value, 3350b57cec5SDimitry Andric "Attempted to default construct a reference element in a tuple");} 3360b57cec5SDimitry Andric 3370b57cec5SDimitry Andric template <class _Alloc> 338*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 3390b57cec5SDimitry Andric __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a) 3400b57cec5SDimitry Andric : __value_(allocator_arg_t(), __a) 3410b57cec5SDimitry Andric {static_assert(!is_reference<_Hp>::value, 3420b57cec5SDimitry Andric "Attempted to default construct a reference element in a tuple");} 3430b57cec5SDimitry Andric 3440b57cec5SDimitry Andric template <class _Alloc> 345*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 3460b57cec5SDimitry Andric __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) 3470b57cec5SDimitry Andric : __value_(__a) 3480b57cec5SDimitry Andric {static_assert(!is_reference<_Hp>::value, 3490b57cec5SDimitry Andric "Attempted to default construct a reference element in a tuple");} 3500b57cec5SDimitry Andric 3510b57cec5SDimitry Andric template <class _Tp, 352349cc55cSDimitry Andric class = __enable_if_t< 3530b57cec5SDimitry Andric _And< 354bdd1243dSDimitry Andric _IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, 3550b57cec5SDimitry Andric is_constructible<_Hp, _Tp> 3560b57cec5SDimitry Andric >::value 3570b57cec5SDimitry Andric > 3580b57cec5SDimitry Andric > 359*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 3600b57cec5SDimitry Andric explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) 361*5f757f3fSDimitry Andric : __value_(std::forward<_Tp>(__t)) 3620b57cec5SDimitry Andric {static_assert(__can_bind_reference<_Tp&&>(), 3630b57cec5SDimitry Andric "Attempted construction of reference element binds to a temporary whose lifetime has ended");} 3640b57cec5SDimitry Andric 3650b57cec5SDimitry Andric template <class _Tp, class _Alloc> 366*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 3670b57cec5SDimitry Andric explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t) 368*5f757f3fSDimitry Andric : __value_(std::forward<_Tp>(__t)) 3690b57cec5SDimitry Andric {static_assert(__can_bind_reference<_Tp&&>(), 3700b57cec5SDimitry Andric "Attempted construction of reference element binds to a temporary whose lifetime has ended");} 3710b57cec5SDimitry Andric 3720b57cec5SDimitry Andric template <class _Tp, class _Alloc> 373*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 3740b57cec5SDimitry Andric explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t) 375*5f757f3fSDimitry Andric : __value_(allocator_arg_t(), __a, std::forward<_Tp>(__t)) 3760b57cec5SDimitry Andric {static_assert(!is_reference<_Hp>::value, 3770b57cec5SDimitry Andric "Attempted to uses-allocator construct a reference element in a tuple");} 3780b57cec5SDimitry Andric 3790b57cec5SDimitry Andric template <class _Tp, class _Alloc> 380*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 3810b57cec5SDimitry Andric explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t) 382*5f757f3fSDimitry Andric : __value_(std::forward<_Tp>(__t), __a) 3830b57cec5SDimitry Andric {static_assert(!is_reference<_Hp>::value, 3840b57cec5SDimitry Andric "Attempted to uses-allocator construct a reference element in a tuple");} 3850b57cec5SDimitry Andric 38606c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI __tuple_leaf(const __tuple_leaf& __t) = default; 38706c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI __tuple_leaf(__tuple_leaf&& __t) = default; 3880b57cec5SDimitry Andric 389*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 3900b57cec5SDimitry Andric int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value) 3910b57cec5SDimitry Andric { 392*5f757f3fSDimitry Andric std::swap(*this, __t); 3930b57cec5SDimitry Andric return 0; 3940b57cec5SDimitry Andric } 3950b57cec5SDimitry Andric 396*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 39781ad6265SDimitry Andric int swap(const __tuple_leaf& __t) const _NOEXCEPT_(__is_nothrow_swappable<const __tuple_leaf>::value) { 398*5f757f3fSDimitry Andric std::swap(*this, __t); 39981ad6265SDimitry Andric return 0; 40081ad6265SDimitry Andric } 40181ad6265SDimitry Andric 402*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get() _NOEXCEPT {return __value_;} 403*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get() const _NOEXCEPT {return __value_;} 4040b57cec5SDimitry Andric}; 4050b57cec5SDimitry Andric 4060b57cec5SDimitry Andrictemplate <size_t _Ip, class _Hp> 4070b57cec5SDimitry Andricclass __tuple_leaf<_Ip, _Hp, true> 4080b57cec5SDimitry Andric : private _Hp 4090b57cec5SDimitry Andric{ 410bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 4110b57cec5SDimitry Andric __tuple_leaf& operator=(const __tuple_leaf&); 4120b57cec5SDimitry Andricpublic: 413*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf() 4140b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {} 4150b57cec5SDimitry Andric 4160b57cec5SDimitry Andric template <class _Alloc> 417*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 4180b57cec5SDimitry Andric __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {} 4190b57cec5SDimitry Andric 4200b57cec5SDimitry Andric template <class _Alloc> 421*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 4220b57cec5SDimitry Andric __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a) 4230b57cec5SDimitry Andric : _Hp(allocator_arg_t(), __a) {} 4240b57cec5SDimitry Andric 4250b57cec5SDimitry Andric template <class _Alloc> 426*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 4270b57cec5SDimitry Andric __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) 4280b57cec5SDimitry Andric : _Hp(__a) {} 4290b57cec5SDimitry Andric 4300b57cec5SDimitry Andric template <class _Tp, 431349cc55cSDimitry Andric class = __enable_if_t< 4320b57cec5SDimitry Andric _And< 433bdd1243dSDimitry Andric _IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, 4340b57cec5SDimitry Andric is_constructible<_Hp, _Tp> 4350b57cec5SDimitry Andric >::value 4360b57cec5SDimitry Andric > 4370b57cec5SDimitry Andric > 438*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 4390b57cec5SDimitry Andric explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value)) 440*5f757f3fSDimitry Andric : _Hp(std::forward<_Tp>(__t)) {} 4410b57cec5SDimitry Andric 4420b57cec5SDimitry Andric template <class _Tp, class _Alloc> 443*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 4440b57cec5SDimitry Andric explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t) 445*5f757f3fSDimitry Andric : _Hp(std::forward<_Tp>(__t)) {} 4460b57cec5SDimitry Andric 4470b57cec5SDimitry Andric template <class _Tp, class _Alloc> 448*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 4490b57cec5SDimitry Andric explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t) 450*5f757f3fSDimitry Andric : _Hp(allocator_arg_t(), __a, std::forward<_Tp>(__t)) {} 4510b57cec5SDimitry Andric 4520b57cec5SDimitry Andric template <class _Tp, class _Alloc> 453*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 4540b57cec5SDimitry Andric explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t) 455*5f757f3fSDimitry Andric : _Hp(std::forward<_Tp>(__t), __a) {} 4560b57cec5SDimitry Andric 4570b57cec5SDimitry Andric __tuple_leaf(__tuple_leaf const &) = default; 4580b57cec5SDimitry Andric __tuple_leaf(__tuple_leaf &&) = default; 4590b57cec5SDimitry Andric 460*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 4610b57cec5SDimitry Andric int 4620b57cec5SDimitry Andric swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value) 4630b57cec5SDimitry Andric { 464*5f757f3fSDimitry Andric std::swap(*this, __t); 4650b57cec5SDimitry Andric return 0; 4660b57cec5SDimitry Andric } 4670b57cec5SDimitry Andric 468*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 46981ad6265SDimitry Andric int swap(const __tuple_leaf& __rhs) const _NOEXCEPT_(__is_nothrow_swappable<const __tuple_leaf>::value) { 470*5f757f3fSDimitry Andric std::swap(*this, __rhs); 47181ad6265SDimitry Andric return 0; 47281ad6265SDimitry Andric } 47381ad6265SDimitry Andric 474*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);} 475*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);} 4760b57cec5SDimitry Andric}; 4770b57cec5SDimitry Andric 4780b57cec5SDimitry Andrictemplate <class ..._Tp> 479*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 4800b57cec5SDimitry Andricvoid __swallow(_Tp&&...) _NOEXCEPT {} 4810b57cec5SDimitry Andric 4820b57cec5SDimitry Andrictemplate <class _Tp> 4830b57cec5SDimitry Andricstruct __all_default_constructible; 4840b57cec5SDimitry Andric 4850b57cec5SDimitry Andrictemplate <class ..._Tp> 4860b57cec5SDimitry Andricstruct __all_default_constructible<__tuple_types<_Tp...>> 4870b57cec5SDimitry Andric : __all<is_default_constructible<_Tp>::value...> 4880b57cec5SDimitry Andric{ }; 4890b57cec5SDimitry Andric 4900b57cec5SDimitry Andric// __tuple_impl 4910b57cec5SDimitry Andric 4920b57cec5SDimitry Andrictemplate<class _Indx, class ..._Tp> struct __tuple_impl; 4930b57cec5SDimitry Andric 4940b57cec5SDimitry Andrictemplate<size_t ..._Indx, class ..._Tp> 4950b57cec5SDimitry Andricstruct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...> 4960b57cec5SDimitry Andric : public __tuple_leaf<_Indx, _Tp>... 4970b57cec5SDimitry Andric{ 498*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI 499fe6060f1SDimitry Andric constexpr __tuple_impl() 5000b57cec5SDimitry Andric _NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {} 5010b57cec5SDimitry Andric 5020b57cec5SDimitry Andric template <size_t ..._Uf, class ..._Tf, 5030b57cec5SDimitry Andric size_t ..._Ul, class ..._Tl, class ..._Up> 504*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 5050b57cec5SDimitry Andric explicit 5060b57cec5SDimitry Andric __tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>, 5070b57cec5SDimitry Andric __tuple_indices<_Ul...>, __tuple_types<_Tl...>, 5080b57cec5SDimitry Andric _Up&&... __u) 5090b57cec5SDimitry Andric _NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value && 5100b57cec5SDimitry Andric __all<is_nothrow_default_constructible<_Tl>::value...>::value)) : 511*5f757f3fSDimitry Andric __tuple_leaf<_Uf, _Tf>(std::forward<_Up>(__u))..., 5120b57cec5SDimitry Andric __tuple_leaf<_Ul, _Tl>()... 5130b57cec5SDimitry Andric {} 5140b57cec5SDimitry Andric 5150b57cec5SDimitry Andric template <class _Alloc, size_t ..._Uf, class ..._Tf, 5160b57cec5SDimitry Andric size_t ..._Ul, class ..._Tl, class ..._Up> 517*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 5180b57cec5SDimitry Andric explicit 5190b57cec5SDimitry Andric __tuple_impl(allocator_arg_t, const _Alloc& __a, 5200b57cec5SDimitry Andric __tuple_indices<_Uf...>, __tuple_types<_Tf...>, 5210b57cec5SDimitry Andric __tuple_indices<_Ul...>, __tuple_types<_Tl...>, 5220b57cec5SDimitry Andric _Up&&... __u) : 5230b57cec5SDimitry Andric __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a, 524*5f757f3fSDimitry Andric std::forward<_Up>(__u))..., 5250b57cec5SDimitry Andric __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)... 5260b57cec5SDimitry Andric {} 5270b57cec5SDimitry Andric 5280b57cec5SDimitry Andric template <class _Tuple, 529753f127fSDimitry Andric class = __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value> 5300b57cec5SDimitry Andric > 531*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 5320b57cec5SDimitry Andric __tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx, 5330b57cec5SDimitry Andric typename __make_tuple_types<_Tuple>::type>::type>::value...>::value)) 534*5f757f3fSDimitry Andric : __tuple_leaf<_Indx, _Tp>(std::forward<typename tuple_element<_Indx, 535*5f757f3fSDimitry Andric typename __make_tuple_types<_Tuple>::type>::type>(std::get<_Indx>(__t)))... 5360b57cec5SDimitry Andric {} 5370b57cec5SDimitry Andric 5380b57cec5SDimitry Andric template <class _Alloc, class _Tuple, 539753f127fSDimitry Andric class = __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value> 5400b57cec5SDimitry Andric > 541*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 5420b57cec5SDimitry Andric __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) 5430b57cec5SDimitry Andric : __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx, 5440b57cec5SDimitry Andric typename __make_tuple_types<_Tuple>::type>::type>(), __a, 545*5f757f3fSDimitry Andric std::forward<typename tuple_element<_Indx, 546*5f757f3fSDimitry Andric typename __make_tuple_types<_Tuple>::type>::type>(std::get<_Indx>(__t)))... 5470b57cec5SDimitry Andric {} 5480b57cec5SDimitry Andric 5490b57cec5SDimitry Andric __tuple_impl(const __tuple_impl&) = default; 5500b57cec5SDimitry Andric __tuple_impl(__tuple_impl&&) = default; 5510b57cec5SDimitry Andric 552*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 5530b57cec5SDimitry Andric void swap(__tuple_impl& __t) 5540b57cec5SDimitry Andric _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) 5550b57cec5SDimitry Andric { 556*5f757f3fSDimitry Andric std::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...); 5570b57cec5SDimitry Andric } 55881ad6265SDimitry Andric 559*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 56081ad6265SDimitry Andric void swap(const __tuple_impl& __t) const 56181ad6265SDimitry Andric _NOEXCEPT_(__all<__is_nothrow_swappable<const _Tp>::value...>::value) 56281ad6265SDimitry Andric { 563*5f757f3fSDimitry Andric std::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t))...); 56481ad6265SDimitry Andric } 5650b57cec5SDimitry Andric}; 5660b57cec5SDimitry Andric 567fe6060f1SDimitry Andrictemplate<class _Dest, class _Source, size_t ..._Np> 568*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 569fe6060f1SDimitry Andricvoid __memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) { 570*5f757f3fSDimitry Andric std::__swallow(((std::get<_Np>(__dest) = std::get<_Np>(__source)), void(), 0)...); 571fe6060f1SDimitry Andric} 5720b57cec5SDimitry Andric 573fe6060f1SDimitry Andrictemplate<class _Dest, class _Source, class ..._Up, size_t ..._Np> 574*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 575fe6060f1SDimitry Andricvoid __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) { 576*5f757f3fSDimitry Andric std::__swallow((( 577*5f757f3fSDimitry Andric std::get<_Np>(__dest) = std::forward<_Up>(std::get<_Np>(__source)) 578fe6060f1SDimitry Andric ), void(), 0)...); 579fe6060f1SDimitry Andric} 5800b57cec5SDimitry Andric 5810b57cec5SDimitry Andrictemplate <class ..._Tp> 5820b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS tuple 5830b57cec5SDimitry Andric{ 5840b57cec5SDimitry Andric typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT; 5850b57cec5SDimitry Andric 5860b57cec5SDimitry Andric _BaseT __base_; 5870b57cec5SDimitry Andric 588bdd1243dSDimitry Andric template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_SINCE_CXX14 5890b57cec5SDimitry Andric typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT; 590bdd1243dSDimitry Andric template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_SINCE_CXX14 5910b57cec5SDimitry Andric const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT; 592bdd1243dSDimitry Andric template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_SINCE_CXX14 5930b57cec5SDimitry Andric typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT; 594bdd1243dSDimitry Andric template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_SINCE_CXX14 5950b57cec5SDimitry Andric const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT; 5960b57cec5SDimitry Andricpublic: 597fe6060f1SDimitry Andric // [tuple.cnstr] 5980b57cec5SDimitry Andric 599*5f757f3fSDimitry Andric_LIBCPP_DIAGNOSTIC_PUSH 600*5f757f3fSDimitry Andric_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wc++20-extensions") 601*5f757f3fSDimitry Andric_LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wc++20-extensions") 602e40139ffSDimitry Andric 603*5f757f3fSDimitry Andric // tuple() constructors (including allocator_arg_t variants) 604fe6060f1SDimitry Andric template <template<class...> class _IsImpDefault = __is_implicitly_default_constructible, 605349cc55cSDimitry Andric template<class...> class _IsDefault = is_default_constructible, __enable_if_t< 606fe6060f1SDimitry Andric _And< 607*5f757f3fSDimitry Andric _IsDefault<_Tp>... 608fe6060f1SDimitry Andric >::value 609fe6060f1SDimitry Andric , int> = 0> 610*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR 611*5f757f3fSDimitry Andric explicit(_Not<_Lazy<_And, _IsImpDefault<_Tp>...> >::value) tuple() 612fe6060f1SDimitry Andric _NOEXCEPT_(_And<is_nothrow_default_constructible<_Tp>...>::value) 613fe6060f1SDimitry Andric { } 6140b57cec5SDimitry Andric 615fe6060f1SDimitry Andric template <class _Alloc, 616fe6060f1SDimitry Andric template<class...> class _IsImpDefault = __is_implicitly_default_constructible, 617349cc55cSDimitry Andric template<class...> class _IsDefault = is_default_constructible, __enable_if_t< 618fe6060f1SDimitry Andric _And< 619*5f757f3fSDimitry Andric _IsDefault<_Tp>... 620fe6060f1SDimitry Andric >::value 621fe6060f1SDimitry Andric , int> = 0> 622*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 623*5f757f3fSDimitry Andric explicit(_Not<_Lazy<_And, _IsImpDefault<_Tp>...> >::value) tuple(allocator_arg_t, _Alloc const& __a) 624fe6060f1SDimitry Andric : __base_(allocator_arg_t(), __a, 625fe6060f1SDimitry Andric __tuple_indices<>(), __tuple_types<>(), 626fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp), 0>::type(), 627fe6060f1SDimitry Andric __tuple_types<_Tp...>()) {} 628fe6060f1SDimitry Andric 629fe6060f1SDimitry Andric // tuple(const T&...) constructors (including allocator_arg_t variants) 630349cc55cSDimitry Andric template <template<class...> class _And = _And, __enable_if_t< 631fe6060f1SDimitry Andric _And< 632fe6060f1SDimitry Andric _BoolConstant<sizeof...(_Tp) >= 1>, 633*5f757f3fSDimitry Andric is_copy_constructible<_Tp>... 634fe6060f1SDimitry Andric >::value 635fe6060f1SDimitry Andric , int> = 0> 636*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 637*5f757f3fSDimitry Andric explicit(_Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> >::value) tuple(const _Tp& ... __t) 638fe6060f1SDimitry Andric _NOEXCEPT_(_And<is_nothrow_copy_constructible<_Tp>...>::value) 639fe6060f1SDimitry Andric : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), 640fe6060f1SDimitry Andric typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), 641fe6060f1SDimitry Andric typename __make_tuple_indices<0>::type(), 642fe6060f1SDimitry Andric typename __make_tuple_types<tuple, 0>::type(), 643fe6060f1SDimitry Andric __t... 644fe6060f1SDimitry Andric ) {} 645fe6060f1SDimitry Andric 646349cc55cSDimitry Andric template <class _Alloc, template<class...> class _And = _And, __enable_if_t< 647fe6060f1SDimitry Andric _And< 648fe6060f1SDimitry Andric _BoolConstant<sizeof...(_Tp) >= 1>, 649*5f757f3fSDimitry Andric is_copy_constructible<_Tp>... 650fe6060f1SDimitry Andric >::value 651fe6060f1SDimitry Andric , int> = 0> 652*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 653*5f757f3fSDimitry Andric explicit(_Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> >::value) tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t) 654fe6060f1SDimitry Andric : __base_(allocator_arg_t(), __a, 655fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp)>::type(), 656fe6060f1SDimitry Andric typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), 657fe6060f1SDimitry Andric typename __make_tuple_indices<0>::type(), 658fe6060f1SDimitry Andric typename __make_tuple_types<tuple, 0>::type(), 659fe6060f1SDimitry Andric __t... 660fe6060f1SDimitry Andric ) {} 661fe6060f1SDimitry Andric 662fe6060f1SDimitry Andric // tuple(U&& ...) constructors (including allocator_arg_t variants) 663fe6060f1SDimitry Andric template <class ..._Up> struct _IsThisTuple : false_type { }; 664bdd1243dSDimitry Andric template <class _Up> struct _IsThisTuple<_Up> : is_same<__remove_cvref_t<_Up>, tuple> { }; 665fe6060f1SDimitry Andric 666fe6060f1SDimitry Andric template <class ..._Up> 667fe6060f1SDimitry Andric struct _EnableUTypesCtor : _And< 668fe6060f1SDimitry Andric _BoolConstant<sizeof...(_Tp) >= 1>, 669fe6060f1SDimitry Andric _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors 670fe6060f1SDimitry Andric is_constructible<_Tp, _Up>... 671fe6060f1SDimitry Andric > { }; 672fe6060f1SDimitry Andric 673349cc55cSDimitry Andric template <class ..._Up, __enable_if_t< 674fe6060f1SDimitry Andric _And< 675fe6060f1SDimitry Andric _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, 676*5f757f3fSDimitry Andric _EnableUTypesCtor<_Up...> 677fe6060f1SDimitry Andric >::value 678fe6060f1SDimitry Andric , int> = 0> 679*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 680*5f757f3fSDimitry Andric explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value) tuple(_Up&&... __u) 681fe6060f1SDimitry Andric _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value)) 682fe6060f1SDimitry Andric : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(), 683fe6060f1SDimitry Andric typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), 684fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), 685fe6060f1SDimitry Andric typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), 686*5f757f3fSDimitry Andric std::forward<_Up>(__u)...) {} 687fe6060f1SDimitry Andric 688349cc55cSDimitry Andric template <class _Alloc, class ..._Up, __enable_if_t< 689fe6060f1SDimitry Andric _And< 690fe6060f1SDimitry Andric _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, 691*5f757f3fSDimitry Andric _EnableUTypesCtor<_Up...> 692fe6060f1SDimitry Andric >::value 693fe6060f1SDimitry Andric , int> = 0> 694*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 695*5f757f3fSDimitry Andric explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value) tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) 696fe6060f1SDimitry Andric : __base_(allocator_arg_t(), __a, 697fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Up)>::type(), 698fe6060f1SDimitry Andric typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), 699fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), 700fe6060f1SDimitry Andric typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), 701*5f757f3fSDimitry Andric std::forward<_Up>(__u)...) {} 702fe6060f1SDimitry Andric 703fe6060f1SDimitry Andric // Copy and move constructors (including the allocator_arg_t variants) 704fe6060f1SDimitry Andric tuple(const tuple&) = default; 7050b57cec5SDimitry Andric tuple(tuple&&) = default; 7060b57cec5SDimitry Andric 707349cc55cSDimitry Andric template <class _Alloc, template<class...> class _And = _And, __enable_if_t< 708fe6060f1SDimitry Andric _And<is_copy_constructible<_Tp>...>::value 709fe6060f1SDimitry Andric , int> = 0> 710*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 711fe6060f1SDimitry Andric tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t) 712fe6060f1SDimitry Andric : __base_(allocator_arg_t(), __alloc, __t) 713fe6060f1SDimitry Andric { } 7140b57cec5SDimitry Andric 715349cc55cSDimitry Andric template <class _Alloc, template<class...> class _And = _And, __enable_if_t< 716fe6060f1SDimitry Andric _And<is_move_constructible<_Tp>...>::value 717fe6060f1SDimitry Andric , int> = 0> 718*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 719fe6060f1SDimitry Andric tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t) 720*5f757f3fSDimitry Andric : __base_(allocator_arg_t(), __alloc, std::move(__t)) 721fe6060f1SDimitry Andric { } 722e40139ffSDimitry Andric 723fe6060f1SDimitry Andric // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants) 72481ad6265SDimitry Andric 725bdd1243dSDimitry Andric template <class _OtherTuple, class _DecayedOtherTuple = __remove_cvref_t<_OtherTuple>, class = void> 72681ad6265SDimitry Andric struct _EnableCtorFromUTypesTuple : false_type {}; 72781ad6265SDimitry Andric 72881ad6265SDimitry Andric template <class _OtherTuple, class... _Up> 72981ad6265SDimitry Andric struct _EnableCtorFromUTypesTuple<_OtherTuple, tuple<_Up...>, 73081ad6265SDimitry Andric // the length of the packs needs to checked first otherwise the 2 packs cannot be expanded simultaneously below 73181ad6265SDimitry Andric __enable_if_t<sizeof...(_Up) == sizeof...(_Tp)>> : _And< 73281ad6265SDimitry Andric // the two conditions below are not in spec. The purpose is to disable the UTypes Ctor when copy/move Ctor can work. 73381ad6265SDimitry Andric // Otherwise, is_constructible can trigger hard error in those cases https://godbolt.org/z/M94cGdKcE 73481ad6265SDimitry Andric _Not<is_same<_OtherTuple, const tuple&> >, 73581ad6265SDimitry Andric _Not<is_same<_OtherTuple, tuple&&> >, 73681ad6265SDimitry Andric is_constructible<_Tp, __copy_cvref_t<_OtherTuple, _Up> >..., 73781ad6265SDimitry Andric _Lazy<_Or, _BoolConstant<sizeof...(_Tp) != 1>, 738fe6060f1SDimitry Andric // _Tp and _Up are 1-element packs - the pack expansions look 739fe6060f1SDimitry Andric // weird to avoid tripping up the type traits in degenerate cases 740fe6060f1SDimitry Andric _Lazy<_And, 74181ad6265SDimitry Andric _Not<is_same<_Tp, _Up> >..., 74281ad6265SDimitry Andric _Not<is_convertible<_OtherTuple, _Tp> >..., 74381ad6265SDimitry Andric _Not<is_constructible<_Tp, _OtherTuple> >... 7440b57cec5SDimitry Andric > 74581ad6265SDimitry Andric > 746fe6060f1SDimitry Andric > {}; 7470b57cec5SDimitry Andric 748349cc55cSDimitry Andric template <class ..._Up, __enable_if_t< 749fe6060f1SDimitry Andric _And< 750*5f757f3fSDimitry Andric _EnableCtorFromUTypesTuple<const tuple<_Up...>&> 7510b57cec5SDimitry Andric >::value 752fe6060f1SDimitry Andric , int> = 0> 753*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 754*5f757f3fSDimitry Andric explicit(_Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> >::value) tuple(const tuple<_Up...>& __t) 755fe6060f1SDimitry Andric _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, const _Up&>...>::value)) 756fe6060f1SDimitry Andric : __base_(__t) 757fe6060f1SDimitry Andric { } 7580b57cec5SDimitry Andric 759349cc55cSDimitry Andric template <class ..._Up, class _Alloc, __enable_if_t< 760fe6060f1SDimitry Andric _And< 761*5f757f3fSDimitry Andric _EnableCtorFromUTypesTuple<const tuple<_Up...>&> 762fe6060f1SDimitry Andric >::value 763fe6060f1SDimitry Andric , int> = 0> 764*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 765*5f757f3fSDimitry Andric explicit(_Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> >::value) tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t) 766fe6060f1SDimitry Andric : __base_(allocator_arg_t(), __a, __t) 767fe6060f1SDimitry Andric { } 7680b57cec5SDimitry Andric 76906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 77081ad6265SDimitry Andric // tuple(tuple<U...>&) constructors (including allocator_arg_t variants) 77181ad6265SDimitry Andric 77281ad6265SDimitry Andric template <class... _Up, enable_if_t< 77381ad6265SDimitry Andric _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr> 77481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 775*5f757f3fSDimitry Andric explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value) 77681ad6265SDimitry Andric tuple(tuple<_Up...>& __t) : __base_(__t) {} 77781ad6265SDimitry Andric 77881ad6265SDimitry Andric template <class _Alloc, class... _Up, enable_if_t< 77981ad6265SDimitry Andric _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr> 78081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 781*5f757f3fSDimitry Andric explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value) 78281ad6265SDimitry Andric tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t) : __base_(allocator_arg_t(), __alloc, __t) {} 78306c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 23 78481ad6265SDimitry Andric 785fe6060f1SDimitry Andric // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants) 786349cc55cSDimitry Andric template <class ..._Up, __enable_if_t< 787fe6060f1SDimitry Andric _And< 788*5f757f3fSDimitry Andric _EnableCtorFromUTypesTuple<tuple<_Up...>&&> 789fe6060f1SDimitry Andric >::value 790fe6060f1SDimitry Andric , int> = 0> 791*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 792*5f757f3fSDimitry Andric explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value) tuple(tuple<_Up...>&& __t) 793fe6060f1SDimitry Andric _NOEXCEPT_((_And<is_nothrow_constructible<_Tp, _Up>...>::value)) 794*5f757f3fSDimitry Andric : __base_(std::move(__t)) 795fe6060f1SDimitry Andric { } 7960b57cec5SDimitry Andric 797349cc55cSDimitry Andric template <class _Alloc, class ..._Up, __enable_if_t< 798fe6060f1SDimitry Andric _And< 799*5f757f3fSDimitry Andric _EnableCtorFromUTypesTuple<tuple<_Up...>&&> 800fe6060f1SDimitry Andric >::value 801fe6060f1SDimitry Andric , int> = 0> 802*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 803*5f757f3fSDimitry Andric explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value) tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t) 804*5f757f3fSDimitry Andric : __base_(allocator_arg_t(), __a, std::move(__t)) 805fe6060f1SDimitry Andric { } 806fe6060f1SDimitry Andric 80706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 80881ad6265SDimitry Andric // tuple(const tuple<U...>&&) constructors (including allocator_arg_t variants) 80981ad6265SDimitry Andric 81081ad6265SDimitry Andric template <class... _Up, enable_if_t< 81181ad6265SDimitry Andric _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr> 81281ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 813*5f757f3fSDimitry Andric explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value) 81481ad6265SDimitry Andric tuple(const tuple<_Up...>&& __t) : __base_(std::move(__t)) {} 81581ad6265SDimitry Andric 81681ad6265SDimitry Andric template <class _Alloc, class... _Up, enable_if_t< 81781ad6265SDimitry Andric _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr> 81881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 819*5f757f3fSDimitry Andric explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value) 82081ad6265SDimitry Andric tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t) 82181ad6265SDimitry Andric : __base_(allocator_arg_t(), __alloc, std::move(__t)) {} 82206c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 23 82381ad6265SDimitry Andric 824fe6060f1SDimitry Andric // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants) 82581ad6265SDimitry Andric 82606c3fb27SDimitry Andric template <template <class...> class _Pred, class _Pair, class _DecayedPair = __remove_cvref_t<_Pair>, class _Tuple = tuple> 82781ad6265SDimitry Andric struct _CtorPredicateFromPair : false_type{}; 82881ad6265SDimitry Andric 82906c3fb27SDimitry Andric template <template <class...> class _Pred, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2> 83006c3fb27SDimitry Andric struct _CtorPredicateFromPair<_Pred, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : _And< 83106c3fb27SDimitry Andric _Pred<_Tp1, __copy_cvref_t<_Pair, _Up1> >, 83206c3fb27SDimitry Andric _Pred<_Tp2, __copy_cvref_t<_Pair, _Up2> > 833fe6060f1SDimitry Andric > {}; 834fe6060f1SDimitry Andric 83581ad6265SDimitry Andric template <class _Pair> 83681ad6265SDimitry Andric struct _EnableCtorFromPair : _CtorPredicateFromPair<is_constructible, _Pair>{}; 83781ad6265SDimitry Andric 83881ad6265SDimitry Andric template <class _Pair> 83981ad6265SDimitry Andric struct _NothrowConstructibleFromPair : _CtorPredicateFromPair<is_nothrow_constructible, _Pair>{}; 84081ad6265SDimitry Andric 841bdd1243dSDimitry Andric template <class _Pair, class _DecayedPair = __remove_cvref_t<_Pair>, class _Tuple = tuple> 84281ad6265SDimitry Andric struct _BothImplicitlyConvertible : false_type{}; 84381ad6265SDimitry Andric 84481ad6265SDimitry Andric template <class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2> 84581ad6265SDimitry Andric struct _BothImplicitlyConvertible<_Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : _And< 84681ad6265SDimitry Andric is_convertible<__copy_cvref_t<_Pair, _Up1>, _Tp1>, 84781ad6265SDimitry Andric is_convertible<__copy_cvref_t<_Pair, _Up2>, _Tp2> 848fe6060f1SDimitry Andric > {}; 849fe6060f1SDimitry Andric 850349cc55cSDimitry Andric template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t< 851fe6060f1SDimitry Andric _And< 852*5f757f3fSDimitry Andric _EnableCtorFromPair<const pair<_Up1, _Up2>&> 853fe6060f1SDimitry Andric >::value 854fe6060f1SDimitry Andric , int> = 0> 855*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 856*5f757f3fSDimitry Andric explicit(_Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> >::value) tuple(const pair<_Up1, _Up2>& __p) 85781ad6265SDimitry Andric _NOEXCEPT_((_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value)) 858fe6060f1SDimitry Andric : __base_(__p) 859fe6060f1SDimitry Andric { } 860fe6060f1SDimitry Andric 861349cc55cSDimitry Andric template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t< 862fe6060f1SDimitry Andric _And< 863*5f757f3fSDimitry Andric _EnableCtorFromPair<const pair<_Up1, _Up2>&> 864fe6060f1SDimitry Andric >::value 865fe6060f1SDimitry Andric , int> = 0> 866*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 867*5f757f3fSDimitry Andric explicit(_Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> >::value) tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p) 868fe6060f1SDimitry Andric : __base_(allocator_arg_t(), __a, __p) 869fe6060f1SDimitry Andric { } 870fe6060f1SDimitry Andric 87106c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 87281ad6265SDimitry Andric // tuple(pair<U1, U2>&) constructors (including allocator_arg_t variants) 873fe6060f1SDimitry Andric 87481ad6265SDimitry Andric template <class _U1, class _U2, enable_if_t< 87581ad6265SDimitry Andric _EnableCtorFromPair<pair<_U1, _U2>&>::value>* = nullptr> 87681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 87781ad6265SDimitry Andric explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value) 87881ad6265SDimitry Andric tuple(pair<_U1, _U2>& __p) : __base_(__p) {} 87981ad6265SDimitry Andric 88081ad6265SDimitry Andric template <class _Alloc, class _U1, class _U2, enable_if_t< 88181ad6265SDimitry Andric _EnableCtorFromPair<std::pair<_U1, _U2>&>::value>* = nullptr> 88281ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 88381ad6265SDimitry Andric explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value) 88481ad6265SDimitry Andric tuple(allocator_arg_t, const _Alloc& __alloc, pair<_U1, _U2>& __p) : __base_(allocator_arg_t(), __alloc, __p) {} 88581ad6265SDimitry Andric#endif 88681ad6265SDimitry Andric 88781ad6265SDimitry Andric // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants) 888fe6060f1SDimitry Andric 889349cc55cSDimitry Andric template <class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t< 890fe6060f1SDimitry Andric _And< 891*5f757f3fSDimitry Andric _EnableCtorFromPair<pair<_Up1, _Up2>&&> 892fe6060f1SDimitry Andric >::value 893fe6060f1SDimitry Andric , int> = 0> 894*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 895*5f757f3fSDimitry Andric explicit(_Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> >::value) tuple(pair<_Up1, _Up2>&& __p) 89681ad6265SDimitry Andric _NOEXCEPT_((_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value)) 897*5f757f3fSDimitry Andric : __base_(std::move(__p)) 898fe6060f1SDimitry Andric { } 899fe6060f1SDimitry Andric 900349cc55cSDimitry Andric template <class _Alloc, class _Up1, class _Up2, template<class...> class _And = _And, __enable_if_t< 901fe6060f1SDimitry Andric _And< 902*5f757f3fSDimitry Andric _EnableCtorFromPair<pair<_Up1, _Up2>&&> 903fe6060f1SDimitry Andric >::value 904fe6060f1SDimitry Andric , int> = 0> 905*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 906*5f757f3fSDimitry Andric explicit(_Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> >::value) tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p) 907*5f757f3fSDimitry Andric : __base_(allocator_arg_t(), __a, std::move(__p)) 908fe6060f1SDimitry Andric { } 909fe6060f1SDimitry Andric 91006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 91181ad6265SDimitry Andric // tuple(const pair<U1, U2>&&) constructors (including allocator_arg_t variants) 91281ad6265SDimitry Andric 91381ad6265SDimitry Andric template <class _U1, class _U2, enable_if_t< 91481ad6265SDimitry Andric _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr> 91581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 91681ad6265SDimitry Andric explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value) 91781ad6265SDimitry Andric tuple(const pair<_U1, _U2>&& __p) : __base_(std::move(__p)) {} 91881ad6265SDimitry Andric 91981ad6265SDimitry Andric template <class _Alloc, class _U1, class _U2, enable_if_t< 92081ad6265SDimitry Andric _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr> 92181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 92281ad6265SDimitry Andric explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value) 92381ad6265SDimitry Andric tuple(allocator_arg_t, const _Alloc& __alloc, const pair<_U1, _U2>&& __p) 92481ad6265SDimitry Andric : __base_(allocator_arg_t(), __alloc, std::move(__p)) {} 92506c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 23 92681ad6265SDimitry Andric 927*5f757f3fSDimitry Andric_LIBCPP_DIAGNOSTIC_POP 928*5f757f3fSDimitry Andric 929fe6060f1SDimitry Andric // [tuple.assign] 930*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 931fe6060f1SDimitry Andric tuple& operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple) 932fe6060f1SDimitry Andric _NOEXCEPT_((_And<is_nothrow_copy_assignable<_Tp>...>::value)) 9330b57cec5SDimitry Andric { 934*5f757f3fSDimitry Andric std::__memberwise_copy_assign(*this, __tuple, 935fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp)>::type()); 9360b57cec5SDimitry Andric return *this; 9370b57cec5SDimitry Andric } 9380b57cec5SDimitry Andric 93906c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 94081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 94181ad6265SDimitry Andric const tuple& operator=(tuple const& __tuple) const 94281ad6265SDimitry Andric requires (_And<is_copy_assignable<const _Tp>...>::value) { 94381ad6265SDimitry Andric std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type()); 94481ad6265SDimitry Andric return *this; 94581ad6265SDimitry Andric } 94681ad6265SDimitry Andric 94781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 94881ad6265SDimitry Andric const tuple& operator=(tuple&& __tuple) const 94981ad6265SDimitry Andric requires (_And<is_assignable<const _Tp&, _Tp>...>::value) { 95081ad6265SDimitry Andric std::__memberwise_forward_assign(*this, 95181ad6265SDimitry Andric std::move(__tuple), 95281ad6265SDimitry Andric __tuple_types<_Tp...>(), 95381ad6265SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp)>::type()); 95481ad6265SDimitry Andric return *this; 95581ad6265SDimitry Andric } 95606c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 23 95781ad6265SDimitry Andric 958*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 959fe6060f1SDimitry Andric tuple& operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple) 960fe6060f1SDimitry Andric _NOEXCEPT_((_And<is_nothrow_move_assignable<_Tp>...>::value)) 9610b57cec5SDimitry Andric { 962*5f757f3fSDimitry Andric std::__memberwise_forward_assign(*this, std::move(__tuple), 963fe6060f1SDimitry Andric __tuple_types<_Tp...>(), 964fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp)>::type()); 9650b57cec5SDimitry Andric return *this; 9660b57cec5SDimitry Andric } 9670b57cec5SDimitry Andric 968349cc55cSDimitry Andric template<class... _Up, __enable_if_t< 969fe6060f1SDimitry Andric _And< 970fe6060f1SDimitry Andric _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, 971fe6060f1SDimitry Andric is_assignable<_Tp&, _Up const&>... 972fe6060f1SDimitry Andric >::value 973fe6060f1SDimitry Andric ,int> = 0> 974*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 975fe6060f1SDimitry Andric tuple& operator=(tuple<_Up...> const& __tuple) 976fe6060f1SDimitry Andric _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value)) 9770b57cec5SDimitry Andric { 978*5f757f3fSDimitry Andric std::__memberwise_copy_assign(*this, __tuple, 979fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp)>::type()); 9800b57cec5SDimitry Andric return *this; 9810b57cec5SDimitry Andric } 9820b57cec5SDimitry Andric 983349cc55cSDimitry Andric template<class... _Up, __enable_if_t< 984fe6060f1SDimitry Andric _And< 985fe6060f1SDimitry Andric _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, 986fe6060f1SDimitry Andric is_assignable<_Tp&, _Up>... 987fe6060f1SDimitry Andric >::value 988fe6060f1SDimitry Andric ,int> = 0> 989*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 990fe6060f1SDimitry Andric tuple& operator=(tuple<_Up...>&& __tuple) 991fe6060f1SDimitry Andric _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value)) 992fe6060f1SDimitry Andric { 993*5f757f3fSDimitry Andric std::__memberwise_forward_assign(*this, std::move(__tuple), 994fe6060f1SDimitry Andric __tuple_types<_Up...>(), 995fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp)>::type()); 996fe6060f1SDimitry Andric return *this; 997fe6060f1SDimitry Andric } 998fe6060f1SDimitry Andric 99981ad6265SDimitry Andric 100006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 100181ad6265SDimitry Andric template <class... _UTypes, enable_if_t< 100281ad6265SDimitry Andric _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>, 100381ad6265SDimitry Andric is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr> 100481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 100581ad6265SDimitry Andric const tuple& operator=(const tuple<_UTypes...>& __u) const { 100681ad6265SDimitry Andric std::__memberwise_copy_assign(*this, 100781ad6265SDimitry Andric __u, 100881ad6265SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp)>::type()); 100981ad6265SDimitry Andric return *this; 101081ad6265SDimitry Andric } 101181ad6265SDimitry Andric 101281ad6265SDimitry Andric template <class... _UTypes, enable_if_t< 101381ad6265SDimitry Andric _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>, 101481ad6265SDimitry Andric is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr> 101581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 101681ad6265SDimitry Andric const tuple& operator=(tuple<_UTypes...>&& __u) const { 101781ad6265SDimitry Andric std::__memberwise_forward_assign(*this, 101881ad6265SDimitry Andric __u, 101981ad6265SDimitry Andric __tuple_types<_UTypes...>(), 102081ad6265SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp)>::type()); 102181ad6265SDimitry Andric return *this; 102281ad6265SDimitry Andric } 102306c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 23 102481ad6265SDimitry Andric 102506c3fb27SDimitry Andric template <template<class...> class _Pred, bool _Const, 1026bdd1243dSDimitry Andric class _Pair, class _DecayedPair = __remove_cvref_t<_Pair>, class _Tuple = tuple> 102781ad6265SDimitry Andric struct _AssignPredicateFromPair : false_type {}; 102881ad6265SDimitry Andric 102906c3fb27SDimitry Andric template <template<class...> class _Pred, bool _Const, 103081ad6265SDimitry Andric class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2> 103106c3fb27SDimitry Andric struct _AssignPredicateFromPair<_Pred, _Const, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > : 103206c3fb27SDimitry Andric _And<_Pred<__maybe_const<_Const, _Tp1>&, __copy_cvref_t<_Pair, _Up1> >, 103306c3fb27SDimitry Andric _Pred<__maybe_const<_Const, _Tp2>&, __copy_cvref_t<_Pair, _Up2> > 103481ad6265SDimitry Andric > {}; 103581ad6265SDimitry Andric 103681ad6265SDimitry Andric template <bool _Const, class _Pair> 103781ad6265SDimitry Andric struct _EnableAssignFromPair : _AssignPredicateFromPair<is_assignable, _Const, _Pair> {}; 103881ad6265SDimitry Andric 103981ad6265SDimitry Andric template <bool _Const, class _Pair> 104081ad6265SDimitry Andric struct _NothrowAssignFromPair : _AssignPredicateFromPair<is_nothrow_assignable, _Const, _Pair> {}; 104181ad6265SDimitry Andric 104206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 104381ad6265SDimitry Andric template <class _U1, class _U2, enable_if_t< 104481ad6265SDimitry Andric _EnableAssignFromPair<true, const pair<_U1, _U2>&>::value>* = nullptr> 104581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 104681ad6265SDimitry Andric const tuple& operator=(const pair<_U1, _U2>& __pair) const 104781ad6265SDimitry Andric noexcept(_NothrowAssignFromPair<true, const pair<_U1, _U2>&>::value) { 104881ad6265SDimitry Andric std::get<0>(*this) = __pair.first; 104981ad6265SDimitry Andric std::get<1>(*this) = __pair.second; 105081ad6265SDimitry Andric return *this; 105181ad6265SDimitry Andric } 105281ad6265SDimitry Andric 105381ad6265SDimitry Andric template <class _U1, class _U2, enable_if_t< 105481ad6265SDimitry Andric _EnableAssignFromPair<true, pair<_U1, _U2>&&>::value>* = nullptr> 105581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 105681ad6265SDimitry Andric const tuple& operator=(pair<_U1, _U2>&& __pair) const 105781ad6265SDimitry Andric noexcept(_NothrowAssignFromPair<true, pair<_U1, _U2>&&>::value) { 105881ad6265SDimitry Andric std::get<0>(*this) = std::move(__pair.first); 105981ad6265SDimitry Andric std::get<1>(*this) = std::move(__pair.second); 106081ad6265SDimitry Andric return *this; 106181ad6265SDimitry Andric } 106206c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 23 106381ad6265SDimitry Andric 106481ad6265SDimitry Andric template<class _Up1, class _Up2, __enable_if_t< 106581ad6265SDimitry Andric _EnableAssignFromPair<false, pair<_Up1, _Up2> const&>::value 1066fe6060f1SDimitry Andric ,int> = 0> 1067*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1068fe6060f1SDimitry Andric tuple& operator=(pair<_Up1, _Up2> const& __pair) 106981ad6265SDimitry Andric _NOEXCEPT_((_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value)) 1070fe6060f1SDimitry Andric { 1071*5f757f3fSDimitry Andric std::get<0>(*this) = __pair.first; 1072*5f757f3fSDimitry Andric std::get<1>(*this) = __pair.second; 1073fe6060f1SDimitry Andric return *this; 1074fe6060f1SDimitry Andric } 1075fe6060f1SDimitry Andric 107681ad6265SDimitry Andric template<class _Up1, class _Up2, __enable_if_t< 107781ad6265SDimitry Andric _EnableAssignFromPair<false, pair<_Up1, _Up2>&&>::value 1078fe6060f1SDimitry Andric ,int> = 0> 1079*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1080fe6060f1SDimitry Andric tuple& operator=(pair<_Up1, _Up2>&& __pair) 108181ad6265SDimitry Andric _NOEXCEPT_((_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value)) 1082fe6060f1SDimitry Andric { 1083*5f757f3fSDimitry Andric std::get<0>(*this) = std::forward<_Up1>(__pair.first); 1084*5f757f3fSDimitry Andric std::get<1>(*this) = std::forward<_Up2>(__pair.second); 1085fe6060f1SDimitry Andric return *this; 1086fe6060f1SDimitry Andric } 1087fe6060f1SDimitry Andric 1088fe6060f1SDimitry Andric // EXTENSION 1089349cc55cSDimitry Andric template<class _Up, size_t _Np, class = __enable_if_t< 1090fe6060f1SDimitry Andric _And< 1091fe6060f1SDimitry Andric _BoolConstant<_Np == sizeof...(_Tp)>, 1092fe6060f1SDimitry Andric is_assignable<_Tp&, _Up const&>... 1093fe6060f1SDimitry Andric >::value 1094fe6060f1SDimitry Andric > > 1095*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1096fe6060f1SDimitry Andric tuple& operator=(array<_Up, _Np> const& __array) 1097fe6060f1SDimitry Andric _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value)) 1098fe6060f1SDimitry Andric { 1099*5f757f3fSDimitry Andric std::__memberwise_copy_assign(*this, __array, 1100fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp)>::type()); 1101fe6060f1SDimitry Andric return *this; 1102fe6060f1SDimitry Andric } 1103fe6060f1SDimitry Andric 1104fe6060f1SDimitry Andric // EXTENSION 1105349cc55cSDimitry Andric template<class _Up, size_t _Np, class = void, class = __enable_if_t< 1106fe6060f1SDimitry Andric _And< 1107fe6060f1SDimitry Andric _BoolConstant<_Np == sizeof...(_Tp)>, 1108fe6060f1SDimitry Andric is_assignable<_Tp&, _Up>... 1109fe6060f1SDimitry Andric >::value 1110fe6060f1SDimitry Andric > > 1111*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1112fe6060f1SDimitry Andric tuple& operator=(array<_Up, _Np>&& __array) 1113fe6060f1SDimitry Andric _NOEXCEPT_((_And<is_nothrow_assignable<_Tp&, _Up>...>::value)) 1114fe6060f1SDimitry Andric { 1115*5f757f3fSDimitry Andric std::__memberwise_forward_assign(*this, std::move(__array), 1116fe6060f1SDimitry Andric __tuple_types<_If<true, _Up, _Tp>...>(), 1117fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp)>::type()); 1118fe6060f1SDimitry Andric return *this; 1119fe6060f1SDimitry Andric } 1120fe6060f1SDimitry Andric 1121fe6060f1SDimitry Andric // [tuple.swap] 1122*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11230b57cec5SDimitry Andric void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) 11240b57cec5SDimitry Andric {__base_.swap(__t.__base_);} 112581ad6265SDimitry Andric 112606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 112781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 112881ad6265SDimitry Andric void swap(const tuple& __t) const noexcept(__all<is_nothrow_swappable_v<const _Tp&>...>::value) { 112981ad6265SDimitry Andric __base_.swap(__t.__base_); 113081ad6265SDimitry Andric } 113106c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 23 11320b57cec5SDimitry Andric}; 11330b57cec5SDimitry Andric 11340b57cec5SDimitry Andrictemplate <> 11350b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS tuple<> 11360b57cec5SDimitry Andric{ 11370b57cec5SDimitry Andricpublic: 113806c3fb27SDimitry Andric constexpr tuple() _NOEXCEPT = default; 11390b57cec5SDimitry Andric template <class _Alloc> 1140*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11410b57cec5SDimitry Andric tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {} 11420b57cec5SDimitry Andric template <class _Alloc> 1143*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11440b57cec5SDimitry Andric tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {} 11450b57cec5SDimitry Andric template <class _Up> 1146*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11470b57cec5SDimitry Andric tuple(array<_Up, 0>) _NOEXCEPT {} 11480b57cec5SDimitry Andric template <class _Alloc, class _Up> 1149*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11500b57cec5SDimitry Andric tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {} 1151*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11520b57cec5SDimitry Andric void swap(tuple&) _NOEXCEPT {} 115306c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 115481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {} 115581ad6265SDimitry Andric#endif 11560b57cec5SDimitry Andric}; 11570b57cec5SDimitry Andric 115806c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 115904eeddc0SDimitry Andrictemplate <class... _TTypes, class... _UTypes, template<class> class _TQual, template<class> class _UQual> 116004eeddc0SDimitry Andric requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; } 116104eeddc0SDimitry Andricstruct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> { 116204eeddc0SDimitry Andric using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; 116304eeddc0SDimitry Andric}; 116404eeddc0SDimitry Andric 116504eeddc0SDimitry Andrictemplate <class... _TTypes, class... _UTypes> 116604eeddc0SDimitry Andric requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; } 116704eeddc0SDimitry Andricstruct common_type<tuple<_TTypes...>, tuple<_UTypes...>> { 116804eeddc0SDimitry Andric using type = tuple<common_type_t<_TTypes, _UTypes>...>; 116904eeddc0SDimitry Andric}; 117006c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 23 117104eeddc0SDimitry Andric 117206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 1173e40139ffSDimitry Andrictemplate <class ..._Tp> 1174e40139ffSDimitry Andrictuple(_Tp...) -> tuple<_Tp...>; 1175e40139ffSDimitry Andrictemplate <class _Tp1, class _Tp2> 1176e40139ffSDimitry Andrictuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>; 1177e40139ffSDimitry Andrictemplate <class _Alloc, class ..._Tp> 1178e40139ffSDimitry Andrictuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>; 1179e40139ffSDimitry Andrictemplate <class _Alloc, class _Tp1, class _Tp2> 1180e40139ffSDimitry Andrictuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>; 1181e40139ffSDimitry Andrictemplate <class _Alloc, class ..._Tp> 1182e40139ffSDimitry Andrictuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>; 11830b57cec5SDimitry Andric#endif 11840b57cec5SDimitry Andric 1185*5f757f3fSDimitry Andrictemplate <class ..._Tp, __enable_if_t<__all<__is_swappable<_Tp>::value...>::value, int> = 0> 1186*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1187*5f757f3fSDimitry Andricvoid 11880b57cec5SDimitry Andricswap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) 11890b57cec5SDimitry Andric _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value) 11900b57cec5SDimitry Andric {__t.swap(__u);} 11910b57cec5SDimitry Andric 119206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 119381ad6265SDimitry Andrictemplate <class... _Tp> 119481ad6265SDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr 119581ad6265SDimitry Andricenable_if_t<__all<is_swappable_v<const _Tp>...>::value, void> 119681ad6265SDimitry Andricswap(const tuple<_Tp...>& __lhs, const tuple<_Tp...>& __rhs) 119781ad6265SDimitry Andric noexcept(__all<is_nothrow_swappable_v<const _Tp>...>::value) { 119881ad6265SDimitry Andric __lhs.swap(__rhs); 119981ad6265SDimitry Andric} 120081ad6265SDimitry Andric#endif 120181ad6265SDimitry Andric 12020b57cec5SDimitry Andric// get 12030b57cec5SDimitry Andric 12040b57cec5SDimitry Andrictemplate <size_t _Ip, class ..._Tp> 1205*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 12060b57cec5SDimitry Andrictypename tuple_element<_Ip, tuple<_Tp...> >::type& 12070b57cec5SDimitry Andricget(tuple<_Tp...>& __t) _NOEXCEPT 12080b57cec5SDimitry Andric{ 1209349cc55cSDimitry Andric typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type; 12100b57cec5SDimitry Andric return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get(); 12110b57cec5SDimitry Andric} 12120b57cec5SDimitry Andric 12130b57cec5SDimitry Andrictemplate <size_t _Ip, class ..._Tp> 1214*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 12150b57cec5SDimitry Andricconst typename tuple_element<_Ip, tuple<_Tp...> >::type& 12160b57cec5SDimitry Andricget(const tuple<_Tp...>& __t) _NOEXCEPT 12170b57cec5SDimitry Andric{ 1218349cc55cSDimitry Andric typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type; 12190b57cec5SDimitry Andric return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get(); 12200b57cec5SDimitry Andric} 12210b57cec5SDimitry Andric 12220b57cec5SDimitry Andrictemplate <size_t _Ip, class ..._Tp> 1223*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 12240b57cec5SDimitry Andrictypename tuple_element<_Ip, tuple<_Tp...> >::type&& 12250b57cec5SDimitry Andricget(tuple<_Tp...>&& __t) _NOEXCEPT 12260b57cec5SDimitry Andric{ 1227349cc55cSDimitry Andric typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type; 12280b57cec5SDimitry Andric return static_cast<type&&>( 12290b57cec5SDimitry Andric static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get()); 12300b57cec5SDimitry Andric} 12310b57cec5SDimitry Andric 12320b57cec5SDimitry Andrictemplate <size_t _Ip, class ..._Tp> 1233*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 12340b57cec5SDimitry Andricconst typename tuple_element<_Ip, tuple<_Tp...> >::type&& 12350b57cec5SDimitry Andricget(const tuple<_Tp...>&& __t) _NOEXCEPT 12360b57cec5SDimitry Andric{ 1237349cc55cSDimitry Andric typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type; 12380b57cec5SDimitry Andric return static_cast<const type&&>( 12390b57cec5SDimitry Andric static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get()); 12400b57cec5SDimitry Andric} 12410b57cec5SDimitry Andric 124206c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 12430b57cec5SDimitry Andric 12440b57cec5SDimitry Andricnamespace __find_detail { 12450b57cec5SDimitry Andric 1246fe6060f1SDimitry Andricstatic constexpr size_t __not_found = static_cast<size_t>(-1); 12470b57cec5SDimitry Andricstatic constexpr size_t __ambiguous = __not_found - 1; 12480b57cec5SDimitry Andric 1249*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 12500b57cec5SDimitry Andricconstexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) { 12510b57cec5SDimitry Andric return !__matches ? __res : 12520b57cec5SDimitry Andric (__res == __not_found ? __curr_i : __ambiguous); 12530b57cec5SDimitry Andric} 12540b57cec5SDimitry Andric 12550b57cec5SDimitry Andrictemplate <size_t _Nx> 1256*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 12570b57cec5SDimitry Andricconstexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) { 12580b57cec5SDimitry Andric return __i == _Nx ? __not_found : 1259bdd1243dSDimitry Andric __find_detail::__find_idx_return(__i, __find_detail::__find_idx(__i + 1, __matches), __matches[__i]); 12600b57cec5SDimitry Andric} 12610b57cec5SDimitry Andric 12620b57cec5SDimitry Andrictemplate <class _T1, class ..._Args> 12630b57cec5SDimitry Andricstruct __find_exactly_one_checked { 12640b57cec5SDimitry Andric static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...}; 12650b57cec5SDimitry Andric static constexpr size_t value = __find_detail::__find_idx(0, __matches); 12660b57cec5SDimitry Andric static_assert(value != __not_found, "type not found in type list" ); 12670b57cec5SDimitry Andric static_assert(value != __ambiguous, "type occurs more than once in type list"); 12680b57cec5SDimitry Andric}; 12690b57cec5SDimitry Andric 12700b57cec5SDimitry Andrictemplate <class _T1> 12710b57cec5SDimitry Andricstruct __find_exactly_one_checked<_T1> { 12720b57cec5SDimitry Andric static_assert(!is_same<_T1, _T1>::value, "type not in empty type list"); 12730b57cec5SDimitry Andric}; 12740b57cec5SDimitry Andric 12750eae32dcSDimitry Andric} // namespace __find_detail 12760b57cec5SDimitry Andric 12770b57cec5SDimitry Andrictemplate <typename _T1, typename... _Args> 12780b57cec5SDimitry Andricstruct __find_exactly_one_t 12790b57cec5SDimitry Andric : public __find_detail::__find_exactly_one_checked<_T1, _Args...> { 12800b57cec5SDimitry Andric}; 12810b57cec5SDimitry Andric 12820b57cec5SDimitry Andrictemplate <class _T1, class... _Args> 1283*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 12840b57cec5SDimitry Andricconstexpr _T1& get(tuple<_Args...>& __tup) noexcept 12850b57cec5SDimitry Andric{ 1286*5f757f3fSDimitry Andric return std::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); 12870b57cec5SDimitry Andric} 12880b57cec5SDimitry Andric 12890b57cec5SDimitry Andrictemplate <class _T1, class... _Args> 1290*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 12910b57cec5SDimitry Andricconstexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept 12920b57cec5SDimitry Andric{ 1293*5f757f3fSDimitry Andric return std::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); 12940b57cec5SDimitry Andric} 12950b57cec5SDimitry Andric 12960b57cec5SDimitry Andrictemplate <class _T1, class... _Args> 1297*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 12980b57cec5SDimitry Andricconstexpr _T1&& get(tuple<_Args...>&& __tup) noexcept 12990b57cec5SDimitry Andric{ 1300*5f757f3fSDimitry Andric return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup)); 13010b57cec5SDimitry Andric} 13020b57cec5SDimitry Andric 13030b57cec5SDimitry Andrictemplate <class _T1, class... _Args> 1304*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 13050b57cec5SDimitry Andricconstexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept 13060b57cec5SDimitry Andric{ 1307*5f757f3fSDimitry Andric return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup)); 13080b57cec5SDimitry Andric} 13090b57cec5SDimitry Andric 13100b57cec5SDimitry Andric#endif 13110b57cec5SDimitry Andric 13120b57cec5SDimitry Andric// tie 13130b57cec5SDimitry Andric 13140b57cec5SDimitry Andrictemplate <class ..._Tp> 1315*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 13160b57cec5SDimitry Andrictuple<_Tp&...> 13170b57cec5SDimitry Andrictie(_Tp&... __t) _NOEXCEPT 13180b57cec5SDimitry Andric{ 13190b57cec5SDimitry Andric return tuple<_Tp&...>(__t...); 13200b57cec5SDimitry Andric} 13210b57cec5SDimitry Andric 13220b57cec5SDimitry Andrictemplate <class _Up> 13230b57cec5SDimitry Andricstruct __ignore_t 13240b57cec5SDimitry Andric{ 13250b57cec5SDimitry Andric template <class _Tp> 1326*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 13270b57cec5SDimitry Andric const __ignore_t& operator=(_Tp&&) const {return *this;} 13280b57cec5SDimitry Andric}; 13290b57cec5SDimitry Andric 133006c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 133106c3fb27SDimitry Andricinline constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); 133206c3fb27SDimitry Andric# else 13330b57cec5SDimitry Andricnamespace { 1334349cc55cSDimitry Andric constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>(); 13350eae32dcSDimitry Andric} // namespace 133606c3fb27SDimitry Andric# endif 13370b57cec5SDimitry Andric 13380b57cec5SDimitry Andrictemplate <class... _Tp> 1339*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 13400b57cec5SDimitry Andrictuple<typename __unwrap_ref_decay<_Tp>::type...> 13410b57cec5SDimitry Andricmake_tuple(_Tp&&... __t) 13420b57cec5SDimitry Andric{ 1343*5f757f3fSDimitry Andric return tuple<typename __unwrap_ref_decay<_Tp>::type...>(std::forward<_Tp>(__t)...); 13440b57cec5SDimitry Andric} 13450b57cec5SDimitry Andric 13460b57cec5SDimitry Andrictemplate <class... _Tp> 1347*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 13480b57cec5SDimitry Andrictuple<_Tp&&...> 13490b57cec5SDimitry Andricforward_as_tuple(_Tp&&... __t) _NOEXCEPT 13500b57cec5SDimitry Andric{ 1351*5f757f3fSDimitry Andric return tuple<_Tp&&...>(std::forward<_Tp>(__t)...); 13520b57cec5SDimitry Andric} 13530b57cec5SDimitry Andric 13540b57cec5SDimitry Andrictemplate <size_t _Ip> 13550b57cec5SDimitry Andricstruct __tuple_equal 13560b57cec5SDimitry Andric{ 13570b57cec5SDimitry Andric template <class _Tp, class _Up> 1358*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 13590b57cec5SDimitry Andric bool operator()(const _Tp& __x, const _Up& __y) 13600b57cec5SDimitry Andric { 1361*5f757f3fSDimitry Andric return __tuple_equal<_Ip - 1>()(__x, __y) && std::get<_Ip-1>(__x) == std::get<_Ip-1>(__y); 13620b57cec5SDimitry Andric } 13630b57cec5SDimitry Andric}; 13640b57cec5SDimitry Andric 13650b57cec5SDimitry Andrictemplate <> 13660b57cec5SDimitry Andricstruct __tuple_equal<0> 13670b57cec5SDimitry Andric{ 13680b57cec5SDimitry Andric template <class _Tp, class _Up> 1369*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 13700b57cec5SDimitry Andric bool operator()(const _Tp&, const _Up&) 13710b57cec5SDimitry Andric { 13720b57cec5SDimitry Andric return true; 13730b57cec5SDimitry Andric } 13740b57cec5SDimitry Andric}; 13750b57cec5SDimitry Andric 13760b57cec5SDimitry Andrictemplate <class ..._Tp, class ..._Up> 1377*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 13780b57cec5SDimitry Andricbool 13790b57cec5SDimitry Andricoperator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) 13800b57cec5SDimitry Andric{ 13810b57cec5SDimitry Andric static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes"); 13820b57cec5SDimitry Andric return __tuple_equal<sizeof...(_Tp)>()(__x, __y); 13830b57cec5SDimitry Andric} 13840b57cec5SDimitry Andric 138506c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 1386349cc55cSDimitry Andric 1387349cc55cSDimitry Andric// operator<=> 1388349cc55cSDimitry Andric 1389349cc55cSDimitry Andrictemplate <class ..._Tp, class ..._Up, size_t ..._Is> 1390349cc55cSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr 1391349cc55cSDimitry Andricauto 1392349cc55cSDimitry Andric__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) { 1393349cc55cSDimitry Andric common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal; 1394*5f757f3fSDimitry Andric static_cast<void>(((__result = std::__synth_three_way(std::get<_Is>(__x), std::get<_Is>(__y)), __result != 0) || ...)); 1395349cc55cSDimitry Andric return __result; 1396349cc55cSDimitry Andric} 1397349cc55cSDimitry Andric 1398349cc55cSDimitry Andrictemplate <class ..._Tp, class ..._Up> 1399349cc55cSDimitry Andricrequires (sizeof...(_Tp) == sizeof...(_Up)) 1400349cc55cSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr 1401349cc55cSDimitry Andriccommon_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> 1402349cc55cSDimitry Andricoperator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) 1403349cc55cSDimitry Andric{ 1404*5f757f3fSDimitry Andric return std::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{}); 1405349cc55cSDimitry Andric} 1406349cc55cSDimitry Andric 140706c3fb27SDimitry Andric#else // _LIBCPP_STD_VER >= 20 1408349cc55cSDimitry Andric 14090b57cec5SDimitry Andrictemplate <class ..._Tp, class ..._Up> 1410*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 14110b57cec5SDimitry Andricbool 14120b57cec5SDimitry Andricoperator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) 14130b57cec5SDimitry Andric{ 14140b57cec5SDimitry Andric return !(__x == __y); 14150b57cec5SDimitry Andric} 14160b57cec5SDimitry Andric 14170b57cec5SDimitry Andrictemplate <size_t _Ip> 14180b57cec5SDimitry Andricstruct __tuple_less 14190b57cec5SDimitry Andric{ 14200b57cec5SDimitry Andric template <class _Tp, class _Up> 1421*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 14220b57cec5SDimitry Andric bool operator()(const _Tp& __x, const _Up& __y) 14230b57cec5SDimitry Andric { 14240b57cec5SDimitry Andric const size_t __idx = tuple_size<_Tp>::value - _Ip; 1425*5f757f3fSDimitry Andric if (std::get<__idx>(__x) < std::get<__idx>(__y)) 14260b57cec5SDimitry Andric return true; 1427*5f757f3fSDimitry Andric if (std::get<__idx>(__y) < std::get<__idx>(__x)) 14280b57cec5SDimitry Andric return false; 14290b57cec5SDimitry Andric return __tuple_less<_Ip-1>()(__x, __y); 14300b57cec5SDimitry Andric } 14310b57cec5SDimitry Andric}; 14320b57cec5SDimitry Andric 14330b57cec5SDimitry Andrictemplate <> 14340b57cec5SDimitry Andricstruct __tuple_less<0> 14350b57cec5SDimitry Andric{ 14360b57cec5SDimitry Andric template <class _Tp, class _Up> 1437*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 14380b57cec5SDimitry Andric bool operator()(const _Tp&, const _Up&) 14390b57cec5SDimitry Andric { 14400b57cec5SDimitry Andric return false; 14410b57cec5SDimitry Andric } 14420b57cec5SDimitry Andric}; 14430b57cec5SDimitry Andric 14440b57cec5SDimitry Andrictemplate <class ..._Tp, class ..._Up> 1445*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 14460b57cec5SDimitry Andricbool 14470b57cec5SDimitry Andricoperator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) 14480b57cec5SDimitry Andric{ 14490b57cec5SDimitry Andric static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes"); 14500b57cec5SDimitry Andric return __tuple_less<sizeof...(_Tp)>()(__x, __y); 14510b57cec5SDimitry Andric} 14520b57cec5SDimitry Andric 14530b57cec5SDimitry Andrictemplate <class ..._Tp, class ..._Up> 1454*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 14550b57cec5SDimitry Andricbool 14560b57cec5SDimitry Andricoperator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) 14570b57cec5SDimitry Andric{ 14580b57cec5SDimitry Andric return __y < __x; 14590b57cec5SDimitry Andric} 14600b57cec5SDimitry Andric 14610b57cec5SDimitry Andrictemplate <class ..._Tp, class ..._Up> 1462*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 14630b57cec5SDimitry Andricbool 14640b57cec5SDimitry Andricoperator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) 14650b57cec5SDimitry Andric{ 14660b57cec5SDimitry Andric return !(__x < __y); 14670b57cec5SDimitry Andric} 14680b57cec5SDimitry Andric 14690b57cec5SDimitry Andrictemplate <class ..._Tp, class ..._Up> 1470*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 14710b57cec5SDimitry Andricbool 14720b57cec5SDimitry Andricoperator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) 14730b57cec5SDimitry Andric{ 14740b57cec5SDimitry Andric return !(__y < __x); 14750b57cec5SDimitry Andric} 14760b57cec5SDimitry Andric 147706c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 1478349cc55cSDimitry Andric 14790b57cec5SDimitry Andric// tuple_cat 14800b57cec5SDimitry Andric 14810b57cec5SDimitry Andrictemplate <class _Tp, class _Up> struct __tuple_cat_type; 14820b57cec5SDimitry Andric 14830b57cec5SDimitry Andrictemplate <class ..._Ttypes, class ..._Utypes> 14840b57cec5SDimitry Andricstruct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> > 14850b57cec5SDimitry Andric{ 1486349cc55cSDimitry Andric typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type; 14870b57cec5SDimitry Andric}; 14880b57cec5SDimitry Andric 14890b57cec5SDimitry Andrictemplate <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples> 14900b57cec5SDimitry Andricstruct __tuple_cat_return_1 14910b57cec5SDimitry Andric{ 14920b57cec5SDimitry Andric}; 14930b57cec5SDimitry Andric 14940b57cec5SDimitry Andrictemplate <class ..._Types, class _Tuple0> 14950b57cec5SDimitry Andricstruct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0> 14960b57cec5SDimitry Andric{ 149781ad6265SDimitry Andric using type _LIBCPP_NODEBUG = typename __tuple_cat_type< 149881ad6265SDimitry Andric tuple<_Types...>, 1499bdd1243dSDimitry Andric typename __make_tuple_types<__remove_cvref_t<_Tuple0> >::type 150081ad6265SDimitry Andric >::type; 15010b57cec5SDimitry Andric}; 15020b57cec5SDimitry Andric 15030b57cec5SDimitry Andrictemplate <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples> 15040b57cec5SDimitry Andricstruct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...> 15050b57cec5SDimitry Andric : public __tuple_cat_return_1< 15060b57cec5SDimitry Andric typename __tuple_cat_type< 15070b57cec5SDimitry Andric tuple<_Types...>, 1508bdd1243dSDimitry Andric typename __make_tuple_types<__remove_cvref_t<_Tuple0> >::type 15090b57cec5SDimitry Andric >::type, 1510bdd1243dSDimitry Andric __tuple_like_ext<__libcpp_remove_reference_t<_Tuple1> >::value, 15110b57cec5SDimitry Andric _Tuple1, _Tuples...> 15120b57cec5SDimitry Andric{ 15130b57cec5SDimitry Andric}; 15140b57cec5SDimitry Andric 15150b57cec5SDimitry Andrictemplate <class ..._Tuples> struct __tuple_cat_return; 15160b57cec5SDimitry Andric 15170b57cec5SDimitry Andrictemplate <class _Tuple0, class ..._Tuples> 15180b57cec5SDimitry Andricstruct __tuple_cat_return<_Tuple0, _Tuples...> 15190b57cec5SDimitry Andric : public __tuple_cat_return_1<tuple<>, 1520bdd1243dSDimitry Andric __tuple_like_ext<__libcpp_remove_reference_t<_Tuple0> >::value, _Tuple0, 15210b57cec5SDimitry Andric _Tuples...> 15220b57cec5SDimitry Andric{ 15230b57cec5SDimitry Andric}; 15240b57cec5SDimitry Andric 15250b57cec5SDimitry Andrictemplate <> 15260b57cec5SDimitry Andricstruct __tuple_cat_return<> 15270b57cec5SDimitry Andric{ 1528349cc55cSDimitry Andric typedef _LIBCPP_NODEBUG tuple<> type; 15290b57cec5SDimitry Andric}; 15300b57cec5SDimitry Andric 1531*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 15320b57cec5SDimitry Andrictuple<> 15330b57cec5SDimitry Andrictuple_cat() 15340b57cec5SDimitry Andric{ 15350b57cec5SDimitry Andric return tuple<>(); 15360b57cec5SDimitry Andric} 15370b57cec5SDimitry Andric 15380b57cec5SDimitry Andrictemplate <class _Rp, class _Indices, class _Tuple0, class ..._Tuples> 15390b57cec5SDimitry Andricstruct __tuple_cat_return_ref_imp; 15400b57cec5SDimitry Andric 15410b57cec5SDimitry Andrictemplate <class ..._Types, size_t ..._I0, class _Tuple0> 15420b57cec5SDimitry Andricstruct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0> 15430b57cec5SDimitry Andric{ 1544bdd1243dSDimitry Andric typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0; 154506c3fb27SDimitry Andric typedef tuple<_Types..., __apply_cv_t<_Tuple0, typename tuple_element<_I0, _T0>::type>&&...> type; 15460b57cec5SDimitry Andric}; 15470b57cec5SDimitry Andric 15480b57cec5SDimitry Andrictemplate <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples> 15490b57cec5SDimitry Andricstruct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, 15500b57cec5SDimitry Andric _Tuple0, _Tuple1, _Tuples...> 15510b57cec5SDimitry Andric : public __tuple_cat_return_ref_imp< 155206c3fb27SDimitry Andric tuple<_Types..., __apply_cv_t<_Tuple0, 155306c3fb27SDimitry Andric typename tuple_element<_I0, __libcpp_remove_reference_t<_Tuple0>>::type>&&...>, 1554bdd1243dSDimitry Andric typename __make_tuple_indices<tuple_size<__libcpp_remove_reference_t<_Tuple1> >::value>::type, 15550b57cec5SDimitry Andric _Tuple1, _Tuples...> 15560b57cec5SDimitry Andric{ 15570b57cec5SDimitry Andric}; 15580b57cec5SDimitry Andric 15590b57cec5SDimitry Andrictemplate <class _Tuple0, class ..._Tuples> 15600b57cec5SDimitry Andricstruct __tuple_cat_return_ref 15610b57cec5SDimitry Andric : public __tuple_cat_return_ref_imp<tuple<>, 15620b57cec5SDimitry Andric typename __make_tuple_indices< 1563bdd1243dSDimitry Andric tuple_size<__libcpp_remove_reference_t<_Tuple0> >::value 15640b57cec5SDimitry Andric >::type, _Tuple0, _Tuples...> 15650b57cec5SDimitry Andric{ 15660b57cec5SDimitry Andric}; 15670b57cec5SDimitry Andric 15680b57cec5SDimitry Andrictemplate <class _Types, class _I0, class _J0> 15690b57cec5SDimitry Andricstruct __tuple_cat; 15700b57cec5SDimitry Andric 15710b57cec5SDimitry Andrictemplate <class ..._Types, size_t ..._I0, size_t ..._J0> 15720b57cec5SDimitry Andricstruct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> > 15730b57cec5SDimitry Andric{ 15740b57cec5SDimitry Andric template <class _Tuple0> 1575*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 15760b57cec5SDimitry Andric typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type 15770b57cec5SDimitry Andric operator()(tuple<_Types...> __t, _Tuple0&& __t0) 15780b57cec5SDimitry Andric { 157981ad6265SDimitry Andric (void)__t; // avoid unused parameter warning on GCC when _I0 is empty 1580*5f757f3fSDimitry Andric return std::forward_as_tuple( 1581*5f757f3fSDimitry Andric std::forward<_Types>(std::get<_I0>(__t))..., 1582*5f757f3fSDimitry Andric std::get<_J0>(std::forward<_Tuple0>(__t0))...); 15830b57cec5SDimitry Andric } 15840b57cec5SDimitry Andric 15850b57cec5SDimitry Andric template <class _Tuple0, class _Tuple1, class ..._Tuples> 1586*5f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 15870b57cec5SDimitry Andric typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type 15880b57cec5SDimitry Andric operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls) 15890b57cec5SDimitry Andric { 159081ad6265SDimitry Andric (void)__t; // avoid unused parameter warning on GCC when _I0 is empty 1591bdd1243dSDimitry Andric typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0; 1592bdd1243dSDimitry Andric typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple1> _T1; 159306c3fb27SDimitry Andric return __tuple_cat<tuple<_Types..., __apply_cv_t<_Tuple0, typename tuple_element<_J0, _T0>::type>&&...>, 159406c3fb27SDimitry Andric typename __make_tuple_indices<sizeof...(_Types) + tuple_size<_T0>::value>::type, 1595480093f4SDimitry Andric typename __make_tuple_indices<tuple_size<_T1>::value>::type>()( 1596*5f757f3fSDimitry Andric std::forward_as_tuple( 1597*5f757f3fSDimitry Andric std::forward<_Types>(std::get<_I0>(__t))..., 1598*5f757f3fSDimitry Andric std::get<_J0>(std::forward<_Tuple0>(__t0))...), 1599*5f757f3fSDimitry Andric std::forward<_Tuple1>(__t1), std::forward<_Tuples>(__tpls)...); 16000b57cec5SDimitry Andric } 16010b57cec5SDimitry Andric}; 16020b57cec5SDimitry Andric 16030b57cec5SDimitry Andrictemplate <class _Tuple0, class... _Tuples> 1604*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 16050b57cec5SDimitry Andrictypename __tuple_cat_return<_Tuple0, _Tuples...>::type 16060b57cec5SDimitry Andrictuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) 16070b57cec5SDimitry Andric{ 1608bdd1243dSDimitry Andric typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0; 16090b57cec5SDimitry Andric return __tuple_cat<tuple<>, __tuple_indices<>, 16100b57cec5SDimitry Andric typename __make_tuple_indices<tuple_size<_T0>::value>::type>() 1611*5f757f3fSDimitry Andric (tuple<>(), std::forward<_Tuple0>(__t0), 1612*5f757f3fSDimitry Andric std::forward<_Tuples>(__tpls)...); 16130b57cec5SDimitry Andric} 16140b57cec5SDimitry Andric 16150b57cec5SDimitry Andrictemplate <class ..._Tp, class _Alloc> 16160b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc> 16170b57cec5SDimitry Andric : true_type {}; 16180b57cec5SDimitry Andric 16190b57cec5SDimitry Andrictemplate <class _T1, class _T2> 16200b57cec5SDimitry Andrictemplate <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2> 1621*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 16220b57cec5SDimitry Andricpair<_T1, _T2>::pair(piecewise_construct_t, 16230b57cec5SDimitry Andric tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, 16240b57cec5SDimitry Andric __tuple_indices<_I1...>, __tuple_indices<_I2...>) 1625*5f757f3fSDimitry Andric : first(std::forward<_Args1>(std::get<_I1>( __first_args))...), 1626*5f757f3fSDimitry Andric second(std::forward<_Args2>(std::get<_I2>(__second_args))...) 16270b57cec5SDimitry Andric{ 16280b57cec5SDimitry Andric} 16290b57cec5SDimitry Andric 163006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 16310b57cec5SDimitry Andrictemplate <class _Tp> 1632349cc55cSDimitry Andricinline constexpr size_t tuple_size_v = tuple_size<_Tp>::value; 16330b57cec5SDimitry Andric 16340b57cec5SDimitry Andric#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; } 16350b57cec5SDimitry Andric 16360b57cec5SDimitry Andrictemplate <class _Fn, class _Tuple, size_t ..._Id> 1637*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 16380b57cec5SDimitry Andricconstexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t, 16390b57cec5SDimitry Andric __tuple_indices<_Id...>) 16400b57cec5SDimitry Andric_LIBCPP_NOEXCEPT_RETURN( 1641*5f757f3fSDimitry Andric std::__invoke( 1642*5f757f3fSDimitry Andric std::forward<_Fn>(__f), 1643*5f757f3fSDimitry Andric std::get<_Id>(std::forward<_Tuple>(__t))...) 16440b57cec5SDimitry Andric) 16450b57cec5SDimitry Andric 16460b57cec5SDimitry Andrictemplate <class _Fn, class _Tuple> 1647*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 16480b57cec5SDimitry Andricconstexpr decltype(auto) apply(_Fn && __f, _Tuple && __t) 16490b57cec5SDimitry Andric_LIBCPP_NOEXCEPT_RETURN( 1650*5f757f3fSDimitry Andric std::__apply_tuple_impl( 1651*5f757f3fSDimitry Andric std::forward<_Fn>(__f), std::forward<_Tuple>(__t), 16520b57cec5SDimitry Andric typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{}) 16530b57cec5SDimitry Andric) 16540b57cec5SDimitry Andric 16550b57cec5SDimitry Andrictemplate <class _Tp, class _Tuple, size_t... _Idx> 1656*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 16570b57cec5SDimitry Andricconstexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>) 16580b57cec5SDimitry Andric_LIBCPP_NOEXCEPT_RETURN( 1659*5f757f3fSDimitry Andric _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...) 16600b57cec5SDimitry Andric) 16610b57cec5SDimitry Andric 16620b57cec5SDimitry Andrictemplate <class _Tp, class _Tuple> 1663*5f757f3fSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 16640b57cec5SDimitry Andricconstexpr _Tp make_from_tuple(_Tuple&& __t) 16650b57cec5SDimitry Andric_LIBCPP_NOEXCEPT_RETURN( 1666*5f757f3fSDimitry Andric std::__make_from_tuple_impl<_Tp>(std::forward<_Tuple>(__t), 16670b57cec5SDimitry Andric typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{}) 16680b57cec5SDimitry Andric) 16690b57cec5SDimitry Andric 16700b57cec5SDimitry Andric#undef _LIBCPP_NOEXCEPT_RETURN 16710b57cec5SDimitry Andric 167206c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 17 16730b57cec5SDimitry Andric 16740b57cec5SDimitry Andric#endif // !defined(_LIBCPP_CXX03_LANG) 16750b57cec5SDimitry Andric 16760b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 16770b57cec5SDimitry Andric 167806c3fb27SDimitry Andric_LIBCPP_POP_MACROS 167906c3fb27SDimitry Andric 1680bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 1681bdd1243dSDimitry Andric# include <exception> 1682bdd1243dSDimitry Andric# include <iosfwd> 1683bdd1243dSDimitry Andric# include <new> 1684bdd1243dSDimitry Andric# include <type_traits> 1685bdd1243dSDimitry Andric# include <typeinfo> 1686bdd1243dSDimitry Andric# include <utility> 1687bdd1243dSDimitry Andric#endif 1688bdd1243dSDimitry Andric 16890b57cec5SDimitry Andric#endif // _LIBCPP_TUPLE 1690