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 135f757f3fSDimitry Andric// clang-format off 145f757f3fSDimitry 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 135*0fca6ea1SDimitry Andricstruct ignore-type { // exposition only // Since C++26 136*0fca6ea1SDimitry Andric constexpr const ignore-type& 137*0fca6ea1SDimitry Andric operator=(const auto &) const noexcept 138*0fca6ea1SDimitry Andric { return *this; } 139*0fca6ea1SDimitry Andric}; 140*0fca6ea1SDimitry Andricinline constexpr ignore-type ignore; 1410b57cec5SDimitry Andric 1420b57cec5SDimitry Andrictemplate <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14 1430b57cec5SDimitry Andrictemplate <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14 1440b57cec5SDimitry Andrictemplate <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14 1450b57cec5SDimitry Andrictemplate <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14 1460b57cec5SDimitry Andric 1470b57cec5SDimitry Andric// [tuple.apply], calling a function with a tuple of arguments: 1480b57cec5SDimitry Andrictemplate <class F, class Tuple> 149297eecfbSDimitry Andric constexpr decltype(auto) apply(F&& f, Tuple&& t) noexcept(see below); // C++17 noexcept since C++23 1500b57cec5SDimitry Andrictemplate <class T, class Tuple> 1510b57cec5SDimitry Andric constexpr T make_from_tuple(Tuple&& t); // C++17 1520b57cec5SDimitry Andric 1530b57cec5SDimitry Andric// 20.4.1.4, tuple helper classes: 1540b57cec5SDimitry Andrictemplate <class T> struct tuple_size; // undefined 1550b57cec5SDimitry Andrictemplate <class... T> struct tuple_size<tuple<T...>>; 1560b57cec5SDimitry Andrictemplate <class T> 1570b57cec5SDimitry Andric inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17 1580b57cec5SDimitry Andrictemplate <size_t I, class T> struct tuple_element; // undefined 1590b57cec5SDimitry Andrictemplate <size_t I, class... T> struct tuple_element<I, tuple<T...>>; 1600b57cec5SDimitry Andrictemplate <size_t I, class T> 1610b57cec5SDimitry Andric using tuple_element_t = typename tuple_element <I, T>::type; // C++14 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andric// 20.4.1.5, element access: 1640b57cec5SDimitry Andrictemplate <size_t I, class... T> 1650b57cec5SDimitry Andric typename tuple_element<I, tuple<T...>>::type& 1660b57cec5SDimitry Andric get(tuple<T...>&) noexcept; // constexpr in C++14 1670b57cec5SDimitry Andrictemplate <size_t I, class... T> 1680b57cec5SDimitry Andric const typename tuple_element<I, tuple<T...>>::type& 1690b57cec5SDimitry Andric get(const tuple<T...>&) noexcept; // constexpr in C++14 1700b57cec5SDimitry Andrictemplate <size_t I, class... T> 1710b57cec5SDimitry Andric typename tuple_element<I, tuple<T...>>::type&& 1720b57cec5SDimitry Andric get(tuple<T...>&&) noexcept; // constexpr in C++14 1730b57cec5SDimitry Andrictemplate <size_t I, class... T> 1740b57cec5SDimitry Andric const typename tuple_element<I, tuple<T...>>::type&& 1750b57cec5SDimitry Andric get(const tuple<T...>&&) noexcept; // constexpr in C++14 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andrictemplate <class T1, class... T> 1780b57cec5SDimitry Andric constexpr T1& get(tuple<T...>&) noexcept; // C++14 1790b57cec5SDimitry Andrictemplate <class T1, class... T> 1800b57cec5SDimitry Andric constexpr const T1& get(const tuple<T...>&) noexcept; // C++14 1810b57cec5SDimitry Andrictemplate <class T1, class... T> 1820b57cec5SDimitry Andric constexpr T1&& get(tuple<T...>&&) noexcept; // C++14 1830b57cec5SDimitry Andrictemplate <class T1, class... T> 1840b57cec5SDimitry Andric constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14 1850b57cec5SDimitry Andric 1860b57cec5SDimitry Andric// 20.4.1.6, relational operators: 1870b57cec5SDimitry Andrictemplate<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14 188349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20 189349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20 190349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20 191349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20 192349cc55cSDimitry Andrictemplate<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14, removed in C++20 193349cc55cSDimitry Andrictemplate<class... T, class... U> 194349cc55cSDimitry Andric constexpr common_comparison_category_t<synth-three-way-result<T, U>...> 195349cc55cSDimitry Andric operator<=>(const tuple<T...>&, const tuple<U...>&); // since C++20 1960b57cec5SDimitry Andric 1970b57cec5SDimitry Andrictemplate <class... Types, class Alloc> 1980b57cec5SDimitry Andric struct uses_allocator<tuple<Types...>, Alloc>; 1990b57cec5SDimitry Andric 2000b57cec5SDimitry Andrictemplate <class... Types> 2010b57cec5SDimitry Andric void 2020b57cec5SDimitry Andric swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y))); 2030b57cec5SDimitry Andric 20481ad6265SDimitry Andrictemplate <class... Types> 20581ad6265SDimitry Andric constexpr void swap(const tuple<Types...>& x, const tuple<Types...>& y) noexcept(see-below); // C++23 20681ad6265SDimitry Andric 2070b57cec5SDimitry Andric} // std 2080b57cec5SDimitry Andric 2090b57cec5SDimitry Andric*/ 2100b57cec5SDimitry Andric 2115f757f3fSDimitry Andric// clang-format on 2125f757f3fSDimitry Andric 213349cc55cSDimitry Andric#include <__compare/common_comparison_category.h> 214349cc55cSDimitry Andric#include <__compare/synth_three_way.h> 2150b57cec5SDimitry Andric#include <__config> 216bdd1243dSDimitry Andric#include <__functional/invoke.h> 217bdd1243dSDimitry Andric#include <__fwd/array.h> 218*0fca6ea1SDimitry Andric#include <__fwd/pair.h> 21906c3fb27SDimitry Andric#include <__fwd/tuple.h> 220fe6060f1SDimitry Andric#include <__memory/allocator_arg_t.h> 221fe6060f1SDimitry Andric#include <__memory/uses_allocator.h> 222*0fca6ea1SDimitry Andric#include <__tuple/find_index.h> 223*0fca6ea1SDimitry Andric#include <__tuple/ignore.h> 22406c3fb27SDimitry Andric#include <__tuple/make_tuple_types.h> 22506c3fb27SDimitry Andric#include <__tuple/sfinae_helpers.h> 22606c3fb27SDimitry Andric#include <__tuple/tuple_element.h> 22706c3fb27SDimitry Andric#include <__tuple/tuple_indices.h> 22806c3fb27SDimitry Andric#include <__tuple/tuple_like_ext.h> 22906c3fb27SDimitry Andric#include <__tuple/tuple_size.h> 23006c3fb27SDimitry Andric#include <__tuple/tuple_types.h> 231bdd1243dSDimitry Andric#include <__type_traits/common_reference.h> 232bdd1243dSDimitry Andric#include <__type_traits/common_type.h> 233bdd1243dSDimitry Andric#include <__type_traits/conditional.h> 234bdd1243dSDimitry Andric#include <__type_traits/conjunction.h> 235bdd1243dSDimitry Andric#include <__type_traits/copy_cvref.h> 236bdd1243dSDimitry Andric#include <__type_traits/disjunction.h> 237bdd1243dSDimitry Andric#include <__type_traits/is_arithmetic.h> 238bdd1243dSDimitry Andric#include <__type_traits/is_assignable.h> 239bdd1243dSDimitry Andric#include <__type_traits/is_constructible.h> 240bdd1243dSDimitry Andric#include <__type_traits/is_convertible.h> 241bdd1243dSDimitry Andric#include <__type_traits/is_empty.h> 242bdd1243dSDimitry Andric#include <__type_traits/is_final.h> 243bdd1243dSDimitry Andric#include <__type_traits/is_implicitly_default_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_reference.h> 247bdd1243dSDimitry Andric#include <__type_traits/is_same.h> 248bdd1243dSDimitry Andric#include <__type_traits/is_swappable.h> 249*0fca6ea1SDimitry Andric#include <__type_traits/is_trivially_relocatable.h> 250bdd1243dSDimitry Andric#include <__type_traits/lazy.h> 251bdd1243dSDimitry Andric#include <__type_traits/maybe_const.h> 252bdd1243dSDimitry Andric#include <__type_traits/nat.h> 253bdd1243dSDimitry Andric#include <__type_traits/negation.h> 254bdd1243dSDimitry Andric#include <__type_traits/remove_cvref.h> 255bdd1243dSDimitry Andric#include <__type_traits/remove_reference.h> 25606c3fb27SDimitry Andric#include <__type_traits/unwrap_ref.h> 257fe6060f1SDimitry Andric#include <__utility/forward.h> 258349cc55cSDimitry Andric#include <__utility/integer_sequence.h> 259fe6060f1SDimitry Andric#include <__utility/move.h> 26081ad6265SDimitry Andric#include <__utility/piecewise_construct.h> 26181ad6265SDimitry Andric#include <__utility/swap.h> 2620b57cec5SDimitry Andric#include <cstddef> 2630b57cec5SDimitry Andric#include <version> 2640b57cec5SDimitry Andric 26581ad6265SDimitry Andric// standard-mandated includes 266bdd1243dSDimitry Andric 267bdd1243dSDimitry Andric// [tuple.syn] 26881ad6265SDimitry Andric#include <compare> 26981ad6265SDimitry Andric 2700b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 2710b57cec5SDimitry Andric# pragma GCC system_header 2720b57cec5SDimitry Andric#endif 2730b57cec5SDimitry Andric 27406c3fb27SDimitry Andric_LIBCPP_PUSH_MACROS 27506c3fb27SDimitry Andric#include <__undef_macros> 27606c3fb27SDimitry Andric 2770b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 2780b57cec5SDimitry Andric 2790b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 2800b57cec5SDimitry Andric 2810b57cec5SDimitry Andric// __tuple_leaf 2820b57cec5SDimitry Andric 283cb14a3feSDimitry Andrictemplate <size_t _Ip, class _Hp, bool = is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value > 2840b57cec5SDimitry Andricclass __tuple_leaf; 2850b57cec5SDimitry Andric 2860b57cec5SDimitry Andrictemplate <size_t _Ip, class _Hp, bool _Ep> 287cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void 288*0fca6ea1SDimitry Andricswap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y) noexcept(__is_nothrow_swappable_v<_Hp>) { 2890b57cec5SDimitry Andric swap(__x.get(), __y.get()); 2900b57cec5SDimitry Andric} 2910b57cec5SDimitry Andric 29281ad6265SDimitry Andrictemplate <size_t _Ip, class _Hp, bool _Ep> 293cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void 294*0fca6ea1SDimitry Andricswap(const __tuple_leaf<_Ip, _Hp, _Ep>& __x, 295*0fca6ea1SDimitry Andric const __tuple_leaf<_Ip, _Hp, _Ep>& __y) noexcept(__is_nothrow_swappable_v<const _Hp>) { 29681ad6265SDimitry Andric swap(__x.get(), __y.get()); 29781ad6265SDimitry Andric} 29881ad6265SDimitry Andric 2990b57cec5SDimitry Andrictemplate <size_t _Ip, class _Hp, bool> 300cb14a3feSDimitry Andricclass __tuple_leaf { 3010b57cec5SDimitry Andric _Hp __value_; 3020b57cec5SDimitry Andric 3030b57cec5SDimitry Andric template <class _Tp> 30406c3fb27SDimitry Andric static _LIBCPP_HIDE_FROM_ABI constexpr bool __can_bind_reference() { 3050b57cec5SDimitry Andric# if __has_keyword(__reference_binds_to_temporary) 3060b57cec5SDimitry Andric return !__reference_binds_to_temporary(_Hp, _Tp); 3070b57cec5SDimitry Andric# else 3080b57cec5SDimitry Andric return true; 3090b57cec5SDimitry Andric# endif 3100b57cec5SDimitry Andric } 3110b57cec5SDimitry Andric 3120b57cec5SDimitry Andricpublic: 313*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator=(const __tuple_leaf&) = delete; 314*0fca6ea1SDimitry Andric 315*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf() noexcept(is_nothrow_default_constructible<_Hp>::value) : __value_() { 316cb14a3feSDimitry Andric static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple"); 317cb14a3feSDimitry Andric } 3180b57cec5SDimitry Andric 3190b57cec5SDimitry Andric template <class _Alloc> 320cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 0>, const _Alloc&) : __value_() { 321cb14a3feSDimitry Andric static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple"); 322cb14a3feSDimitry Andric } 3230b57cec5SDimitry Andric 3240b57cec5SDimitry Andric template <class _Alloc> 325cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a) 326cb14a3feSDimitry Andric : __value_(allocator_arg_t(), __a) { 327cb14a3feSDimitry Andric static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple"); 328cb14a3feSDimitry Andric } 3290b57cec5SDimitry Andric 3300b57cec5SDimitry Andric template <class _Alloc> 331cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) : __value_(__a) { 332cb14a3feSDimitry Andric static_assert(!is_reference<_Hp>::value, "Attempted to default construct a reference element in a tuple"); 333cb14a3feSDimitry Andric } 3340b57cec5SDimitry Andric 335*0fca6ea1SDimitry Andric template < 336*0fca6ea1SDimitry Andric class _Tp, 337*0fca6ea1SDimitry Andric __enable_if_t<_And<_IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp> >::value, int> = 0> 338*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI 339*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(_Tp&& __t) noexcept(is_nothrow_constructible<_Hp, _Tp>::value) 340cb14a3feSDimitry Andric : __value_(std::forward<_Tp>(__t)) { 341cb14a3feSDimitry Andric static_assert(__can_bind_reference<_Tp&&>(), 342cb14a3feSDimitry Andric "Attempted construction of reference element binds to a temporary whose lifetime has ended"); 343cb14a3feSDimitry Andric } 3440b57cec5SDimitry Andric 3450b57cec5SDimitry Andric template <class _Tp, class _Alloc> 346*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI 347*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t) 348cb14a3feSDimitry Andric : __value_(std::forward<_Tp>(__t)) { 349cb14a3feSDimitry Andric static_assert(__can_bind_reference<_Tp&&>(), 350cb14a3feSDimitry Andric "Attempted construction of reference element binds to a temporary whose lifetime has ended"); 351cb14a3feSDimitry Andric } 3520b57cec5SDimitry Andric 3530b57cec5SDimitry Andric template <class _Tp, class _Alloc> 354*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI 355*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t) 356cb14a3feSDimitry Andric : __value_(allocator_arg_t(), __a, std::forward<_Tp>(__t)) { 357cb14a3feSDimitry Andric static_assert(!is_reference<_Hp>::value, "Attempted to uses-allocator construct a reference element in a tuple"); 358cb14a3feSDimitry Andric } 3590b57cec5SDimitry Andric 3600b57cec5SDimitry Andric template <class _Tp, class _Alloc> 361*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI 362*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t) 363cb14a3feSDimitry Andric : __value_(std::forward<_Tp>(__t), __a) { 364cb14a3feSDimitry Andric static_assert(!is_reference<_Hp>::value, "Attempted to uses-allocator construct a reference element in a tuple"); 365cb14a3feSDimitry Andric } 3660b57cec5SDimitry Andric 36706c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI __tuple_leaf(const __tuple_leaf& __t) = default; 36806c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI __tuple_leaf(__tuple_leaf&& __t) = default; 3690b57cec5SDimitry Andric 370*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int 371*0fca6ea1SDimitry Andric swap(__tuple_leaf& __t) noexcept(__is_nothrow_swappable_v<__tuple_leaf>) { 3725f757f3fSDimitry Andric std::swap(*this, __t); 3730b57cec5SDimitry Andric return 0; 3740b57cec5SDimitry Andric } 3750b57cec5SDimitry Andric 376cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int swap(const __tuple_leaf& __t) const 377*0fca6ea1SDimitry Andric noexcept(__is_nothrow_swappable_v<const __tuple_leaf>) { 3785f757f3fSDimitry Andric std::swap(*this, __t); 37981ad6265SDimitry Andric return 0; 38081ad6265SDimitry Andric } 38181ad6265SDimitry Andric 3825f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get() _NOEXCEPT { return __value_; } 3835f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get() const _NOEXCEPT { return __value_; } 3840b57cec5SDimitry Andric}; 3850b57cec5SDimitry Andric 3860b57cec5SDimitry Andrictemplate <size_t _Ip, class _Hp> 387cb14a3feSDimitry Andricclass __tuple_leaf<_Ip, _Hp, true> : private _Hp { 3880b57cec5SDimitry Andricpublic: 389*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator=(const __tuple_leaf&) = delete; 390*0fca6ea1SDimitry Andric 391*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf() noexcept(is_nothrow_default_constructible<_Hp>::value) {} 3920b57cec5SDimitry Andric 3930b57cec5SDimitry Andric template <class _Alloc> 394cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 0>, const _Alloc&) {} 3950b57cec5SDimitry Andric 3960b57cec5SDimitry Andric template <class _Alloc> 397cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a) 3980b57cec5SDimitry Andric : _Hp(allocator_arg_t(), __a) {} 3990b57cec5SDimitry Andric 4000b57cec5SDimitry Andric template <class _Alloc> 401cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a) : _Hp(__a) {} 4020b57cec5SDimitry Andric 4030b57cec5SDimitry Andric template <class _Tp, 404*0fca6ea1SDimitry Andric __enable_if_t< _And< _IsNotSame<__remove_cvref_t<_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp> >::value, 405*0fca6ea1SDimitry Andric int> = 0> 406*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI 407*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf(_Tp&& __t) noexcept(is_nothrow_constructible<_Hp, _Tp>::value) 4085f757f3fSDimitry Andric : _Hp(std::forward<_Tp>(__t)) {} 4090b57cec5SDimitry Andric 4100b57cec5SDimitry Andric template <class _Tp, class _Alloc> 411cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t) 4125f757f3fSDimitry Andric : _Hp(std::forward<_Tp>(__t)) {} 4130b57cec5SDimitry Andric 4140b57cec5SDimitry Andric template <class _Tp, class _Alloc> 415cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t) 4165f757f3fSDimitry Andric : _Hp(allocator_arg_t(), __a, std::forward<_Tp>(__t)) {} 4170b57cec5SDimitry Andric 4180b57cec5SDimitry Andric template <class _Tp, class _Alloc> 419cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t) 4205f757f3fSDimitry Andric : _Hp(std::forward<_Tp>(__t), __a) {} 4210b57cec5SDimitry Andric 4220b57cec5SDimitry Andric __tuple_leaf(__tuple_leaf const&) = default; 4230b57cec5SDimitry Andric __tuple_leaf(__tuple_leaf&&) = default; 4240b57cec5SDimitry Andric 425*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int 426*0fca6ea1SDimitry Andric swap(__tuple_leaf& __t) noexcept(__is_nothrow_swappable_v<__tuple_leaf>) { 4275f757f3fSDimitry Andric std::swap(*this, __t); 4280b57cec5SDimitry Andric return 0; 4290b57cec5SDimitry Andric } 4300b57cec5SDimitry Andric 431cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int swap(const __tuple_leaf& __rhs) const 432*0fca6ea1SDimitry Andric noexcept(__is_nothrow_swappable_v<const __tuple_leaf>) { 4335f757f3fSDimitry Andric std::swap(*this, __rhs); 43481ad6265SDimitry Andric return 0; 43581ad6265SDimitry Andric } 43681ad6265SDimitry Andric 4375f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get() _NOEXCEPT { return static_cast<_Hp&>(*this); } 438cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get() const _NOEXCEPT { 439cb14a3feSDimitry Andric return static_cast<const _Hp&>(*this); 440cb14a3feSDimitry Andric } 4410b57cec5SDimitry Andric}; 4420b57cec5SDimitry Andric 4430b57cec5SDimitry Andrictemplate <class... _Tp> 444cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __swallow(_Tp&&...) _NOEXCEPT {} 4450b57cec5SDimitry Andric 4460b57cec5SDimitry Andrictemplate <class _Tp> 4470b57cec5SDimitry Andricstruct __all_default_constructible; 4480b57cec5SDimitry Andric 4490b57cec5SDimitry Andrictemplate <class... _Tp> 450cb14a3feSDimitry Andricstruct __all_default_constructible<__tuple_types<_Tp...>> : __all<is_default_constructible<_Tp>::value...> {}; 4510b57cec5SDimitry Andric 4520b57cec5SDimitry Andric// __tuple_impl 4530b57cec5SDimitry Andric 454cb14a3feSDimitry Andrictemplate <class _Indx, class... _Tp> 455cb14a3feSDimitry Andricstruct __tuple_impl; 4560b57cec5SDimitry Andric 4570b57cec5SDimitry Andrictemplate <size_t... _Indx, class... _Tp> 4580b57cec5SDimitry Andricstruct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...> 459cb14a3feSDimitry Andric : public __tuple_leaf<_Indx, _Tp>... { 460*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr __tuple_impl() noexcept( 461*0fca6ea1SDimitry Andric __all<is_nothrow_default_constructible<_Tp>::value...>::value) {} 4620b57cec5SDimitry Andric 463cb14a3feSDimitry Andric template <size_t... _Uf, class... _Tf, size_t... _Ul, class... _Tl, class... _Up> 464cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_impl( 465*0fca6ea1SDimitry Andric __tuple_indices<_Uf...>, 466*0fca6ea1SDimitry Andric __tuple_types<_Tf...>, 467*0fca6ea1SDimitry Andric __tuple_indices<_Ul...>, 468*0fca6ea1SDimitry Andric __tuple_types<_Tl...>, 469*0fca6ea1SDimitry Andric _Up&&... __u) noexcept(__all<is_nothrow_constructible<_Tf, _Up>::value...>::value && 470*0fca6ea1SDimitry Andric __all<is_nothrow_default_constructible<_Tl>::value...>::value) 471cb14a3feSDimitry Andric : __tuple_leaf<_Uf, _Tf>(std::forward<_Up>(__u))..., __tuple_leaf<_Ul, _Tl>()... {} 4720b57cec5SDimitry Andric 473cb14a3feSDimitry Andric template <class _Alloc, size_t... _Uf, class... _Tf, size_t... _Ul, class... _Tl, class... _Up> 474cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_impl( 475cb14a3feSDimitry Andric allocator_arg_t, 476cb14a3feSDimitry Andric const _Alloc& __a, 477cb14a3feSDimitry Andric __tuple_indices<_Uf...>, 478cb14a3feSDimitry Andric __tuple_types<_Tf...>, 479cb14a3feSDimitry Andric __tuple_indices<_Ul...>, 480cb14a3feSDimitry Andric __tuple_types<_Tl...>, 481cb14a3feSDimitry Andric _Up&&... __u) 482cb14a3feSDimitry Andric : __tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a, std::forward<_Up>(__u))..., 483cb14a3feSDimitry Andric __tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)... {} 4840b57cec5SDimitry Andric 485*0fca6ea1SDimitry Andric template <class _Tuple, __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value, int> = 0> 486*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(_Tuple&& __t) noexcept( 487cb14a3feSDimitry Andric (__all<is_nothrow_constructible< 488cb14a3feSDimitry Andric _Tp, 489cb14a3feSDimitry Andric typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>::value...>::value)) 490cb14a3feSDimitry Andric : __tuple_leaf<_Indx, _Tp>( 491cb14a3feSDimitry Andric std::forward<typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>( 492cb14a3feSDimitry Andric std::get<_Indx>(__t)))... {} 4930b57cec5SDimitry Andric 494*0fca6ea1SDimitry Andric template <class _Alloc, class _Tuple, __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value, int> = 0> 495cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) 496cb14a3feSDimitry Andric : __tuple_leaf<_Indx, _Tp>( 497cb14a3feSDimitry Andric __uses_alloc_ctor<_Tp, 498cb14a3feSDimitry Andric _Alloc, 499cb14a3feSDimitry Andric typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>(), 500cb14a3feSDimitry Andric __a, 501cb14a3feSDimitry Andric std::forward<typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>( 502cb14a3feSDimitry Andric std::get<_Indx>(__t)))... {} 5030b57cec5SDimitry Andric 5040b57cec5SDimitry Andric __tuple_impl(const __tuple_impl&) = default; 5050b57cec5SDimitry Andric __tuple_impl(__tuple_impl&&) = default; 5060b57cec5SDimitry Andric 507*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void 508*0fca6ea1SDimitry Andric swap(__tuple_impl& __t) noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) { 5095f757f3fSDimitry Andric std::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...); 5100b57cec5SDimitry Andric } 51181ad6265SDimitry Andric 512cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void swap(const __tuple_impl& __t) const 513*0fca6ea1SDimitry Andric noexcept(__all<__is_nothrow_swappable_v<const _Tp>...>::value) { 5145f757f3fSDimitry Andric std::__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t))...); 51581ad6265SDimitry Andric } 5160b57cec5SDimitry Andric}; 5170b57cec5SDimitry Andric 518fe6060f1SDimitry Andrictemplate <class _Dest, class _Source, size_t... _Np> 519cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void 520cb14a3feSDimitry Andric__memberwise_copy_assign(_Dest& __dest, _Source const& __source, __tuple_indices<_Np...>) { 5215f757f3fSDimitry Andric std::__swallow(((std::get<_Np>(__dest) = std::get<_Np>(__source)), void(), 0)...); 522fe6060f1SDimitry Andric} 5230b57cec5SDimitry Andric 524fe6060f1SDimitry Andrictemplate <class _Dest, class _Source, class... _Up, size_t... _Np> 525cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void 526cb14a3feSDimitry Andric__memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up...>, __tuple_indices<_Np...>) { 527cb14a3feSDimitry Andric std::__swallow(((std::get<_Np>(__dest) = std::forward<_Up>(std::get<_Np>(__source))), void(), 0)...); 528fe6060f1SDimitry Andric} 5290b57cec5SDimitry Andric 5300b57cec5SDimitry Andrictemplate <class... _Tp> 531cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS tuple { 5320b57cec5SDimitry Andric typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT; 5330b57cec5SDimitry Andric 5340b57cec5SDimitry Andric _BaseT __base_; 5350b57cec5SDimitry Andric 536cb14a3feSDimitry Andric template <size_t _Jp, class... _Up> 537cb14a3feSDimitry Andric friend _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT; 538cb14a3feSDimitry Andric template <size_t _Jp, class... _Up> 539cb14a3feSDimitry Andric friend _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Jp, tuple<_Up...> >::type& 540cb14a3feSDimitry Andric get(const tuple<_Up...>&) _NOEXCEPT; 541cb14a3feSDimitry Andric template <size_t _Jp, class... _Up> 542cb14a3feSDimitry Andric friend _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Jp, tuple<_Up...> >::type&& 543cb14a3feSDimitry Andric get(tuple<_Up...>&&) _NOEXCEPT; 544cb14a3feSDimitry Andric template <size_t _Jp, class... _Up> 545cb14a3feSDimitry Andric friend _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Jp, tuple<_Up...> >::type&& 546cb14a3feSDimitry Andric get(const tuple<_Up...>&&) _NOEXCEPT; 547cb14a3feSDimitry Andric 5480b57cec5SDimitry Andricpublic: 549*0fca6ea1SDimitry Andric using __trivially_relocatable = __conditional_t<_And<__libcpp_is_trivially_relocatable<_Tp>...>::value, tuple, void>; 5500b57cec5SDimitry Andric 551*0fca6ea1SDimitry Andric // [tuple.cnstr] 552e40139ffSDimitry Andric 5535f757f3fSDimitry Andric // tuple() constructors (including allocator_arg_t variants) 554fe6060f1SDimitry Andric template <template <class...> class _IsImpDefault = __is_implicitly_default_constructible, 555cb14a3feSDimitry Andric template <class...> class _IsDefault = is_default_constructible, 556cb14a3feSDimitry Andric __enable_if_t< _And< _IsDefault<_Tp>... >::value, int> = 0> 557*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr explicit(_Not<_Lazy<_And, _IsImpDefault<_Tp>...> >::value) 558*0fca6ea1SDimitry Andric tuple() noexcept(_And<is_nothrow_default_constructible<_Tp>...>::value) {} 5590b57cec5SDimitry Andric 560fe6060f1SDimitry Andric template <class _Alloc, 561fe6060f1SDimitry Andric template <class...> class _IsImpDefault = __is_implicitly_default_constructible, 562cb14a3feSDimitry Andric template <class...> class _IsDefault = is_default_constructible, 563cb14a3feSDimitry Andric __enable_if_t< _And< _IsDefault<_Tp>... >::value, int> = 0> 564cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, _IsImpDefault<_Tp>...> >::value) 565cb14a3feSDimitry Andric tuple(allocator_arg_t, _Alloc const& __a) 566cb14a3feSDimitry Andric : __base_(allocator_arg_t(), 567cb14a3feSDimitry Andric __a, 568cb14a3feSDimitry Andric __tuple_indices<>(), 569cb14a3feSDimitry Andric __tuple_types<>(), 570fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp), 0>::type(), 571fe6060f1SDimitry Andric __tuple_types<_Tp...>()) {} 572fe6060f1SDimitry Andric 573fe6060f1SDimitry Andric // tuple(const T&...) constructors (including allocator_arg_t variants) 574cb14a3feSDimitry Andric template <template <class...> class _And = _And, 575cb14a3feSDimitry Andric __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) >= 1>, is_copy_constructible<_Tp>... >::value, int> = 0> 576*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI 577*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> >::value) 578*0fca6ea1SDimitry Andric tuple(const _Tp&... __t) noexcept(_And<is_nothrow_copy_constructible<_Tp>...>::value) 579fe6060f1SDimitry Andric : __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(), 580fe6060f1SDimitry Andric typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), 581fe6060f1SDimitry Andric typename __make_tuple_indices<0>::type(), 582fe6060f1SDimitry Andric typename __make_tuple_types<tuple, 0>::type(), 583cb14a3feSDimitry Andric __t...) {} 584fe6060f1SDimitry Andric 585cb14a3feSDimitry Andric template <class _Alloc, 586cb14a3feSDimitry Andric template <class...> class _And = _And, 587cb14a3feSDimitry Andric __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) >= 1>, is_copy_constructible<_Tp>... >::value, int> = 0> 588*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI 589*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<const _Tp&, _Tp>...> >::value) 590cb14a3feSDimitry Andric tuple(allocator_arg_t, const _Alloc& __a, const _Tp&... __t) 591cb14a3feSDimitry Andric : __base_(allocator_arg_t(), 592cb14a3feSDimitry Andric __a, 593fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp)>::type(), 594fe6060f1SDimitry Andric typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(), 595fe6060f1SDimitry Andric typename __make_tuple_indices<0>::type(), 596fe6060f1SDimitry Andric typename __make_tuple_types<tuple, 0>::type(), 597cb14a3feSDimitry Andric __t...) {} 598fe6060f1SDimitry Andric 599fe6060f1SDimitry Andric // tuple(U&& ...) constructors (including allocator_arg_t variants) 600cb14a3feSDimitry Andric template <class... _Up> 601cb14a3feSDimitry Andric struct _IsThisTuple : false_type {}; 602cb14a3feSDimitry Andric template <class _Up> 603cb14a3feSDimitry Andric struct _IsThisTuple<_Up> : is_same<__remove_cvref_t<_Up>, tuple> {}; 604fe6060f1SDimitry Andric 605fe6060f1SDimitry Andric template <class... _Up> 606cb14a3feSDimitry Andric struct _EnableUTypesCtor 607cb14a3feSDimitry Andric : _And< _BoolConstant<sizeof...(_Tp) >= 1>, 608fe6060f1SDimitry Andric _Not<_IsThisTuple<_Up...> >, // extension to allow mis-behaved user constructors 609cb14a3feSDimitry Andric is_constructible<_Tp, _Up>... > {}; 610fe6060f1SDimitry Andric 611cb14a3feSDimitry Andric template <class... _Up, 612cb14a3feSDimitry Andric __enable_if_t< _And< _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, _EnableUTypesCtor<_Up...> >::value, 613cb14a3feSDimitry Andric int> = 0> 614cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value) 615*0fca6ea1SDimitry Andric tuple(_Up&&... __u) noexcept(_And<is_nothrow_constructible<_Tp, _Up>...>::value) 616fe6060f1SDimitry Andric : __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(), 617fe6060f1SDimitry Andric typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), 618fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), 619fe6060f1SDimitry Andric typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), 6205f757f3fSDimitry Andric std::forward<_Up>(__u)...) {} 621fe6060f1SDimitry Andric 622cb14a3feSDimitry Andric template <class _Alloc, 623cb14a3feSDimitry Andric class... _Up, 624cb14a3feSDimitry Andric __enable_if_t< _And< _BoolConstant<sizeof...(_Up) == sizeof...(_Tp)>, _EnableUTypesCtor<_Up...> >::value, 625cb14a3feSDimitry Andric int> = 0> 626cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value) 627cb14a3feSDimitry Andric tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u) 628cb14a3feSDimitry Andric : __base_(allocator_arg_t(), 629cb14a3feSDimitry Andric __a, 630fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Up)>::type(), 631fe6060f1SDimitry Andric typename __make_tuple_types<tuple, sizeof...(_Up)>::type(), 632fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(), 633fe6060f1SDimitry Andric typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(), 6345f757f3fSDimitry Andric std::forward<_Up>(__u)...) {} 635fe6060f1SDimitry Andric 636fe6060f1SDimitry Andric // Copy and move constructors (including the allocator_arg_t variants) 637fe6060f1SDimitry Andric tuple(const tuple&) = default; 6380b57cec5SDimitry Andric tuple(tuple&&) = default; 6390b57cec5SDimitry Andric 640cb14a3feSDimitry Andric template <class _Alloc, 641cb14a3feSDimitry Andric template <class...> class _And = _And, 642cb14a3feSDimitry Andric __enable_if_t< _And<is_copy_constructible<_Tp>...>::value, int> = 0> 643cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc& __alloc, const tuple& __t) 644cb14a3feSDimitry Andric : __base_(allocator_arg_t(), __alloc, __t) {} 6450b57cec5SDimitry Andric 646cb14a3feSDimitry Andric template <class _Alloc, 647cb14a3feSDimitry Andric template <class...> class _And = _And, 648cb14a3feSDimitry Andric __enable_if_t< _And<is_move_constructible<_Tp>...>::value, int> = 0> 649cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc& __alloc, tuple&& __t) 650cb14a3feSDimitry Andric : __base_(allocator_arg_t(), __alloc, std::move(__t)) {} 651e40139ffSDimitry Andric 652fe6060f1SDimitry Andric // tuple(const tuple<U...>&) constructors (including allocator_arg_t variants) 65381ad6265SDimitry Andric 654bdd1243dSDimitry Andric template <class _OtherTuple, class _DecayedOtherTuple = __remove_cvref_t<_OtherTuple>, class = void> 65581ad6265SDimitry Andric struct _EnableCtorFromUTypesTuple : false_type {}; 65681ad6265SDimitry Andric 65781ad6265SDimitry Andric template <class _OtherTuple, class... _Up> 658cb14a3feSDimitry Andric struct _EnableCtorFromUTypesTuple< 659cb14a3feSDimitry Andric _OtherTuple, 660cb14a3feSDimitry Andric tuple<_Up...>, 66181ad6265SDimitry Andric // the length of the packs needs to checked first otherwise the 2 packs cannot be expanded simultaneously below 662cb14a3feSDimitry Andric __enable_if_t<sizeof...(_Up) == sizeof...(_Tp)>> 663cb14a3feSDimitry Andric : _And< 664cb14a3feSDimitry Andric // the two conditions below are not in spec. The purpose is to disable the UTypes Ctor when copy/move Ctor 665cb14a3feSDimitry Andric // can work. Otherwise, is_constructible can trigger hard error in those cases 666cb14a3feSDimitry Andric // https://godbolt.org/z/M94cGdKcE 66781ad6265SDimitry Andric _Not<is_same<_OtherTuple, const tuple&> >, 66881ad6265SDimitry Andric _Not<is_same<_OtherTuple, tuple&&> >, 66981ad6265SDimitry Andric is_constructible<_Tp, __copy_cvref_t<_OtherTuple, _Up> >..., 670cb14a3feSDimitry Andric _Lazy<_Or, 671cb14a3feSDimitry Andric _BoolConstant<sizeof...(_Tp) != 1>, 672fe6060f1SDimitry Andric // _Tp and _Up are 1-element packs - the pack expansions look 673fe6060f1SDimitry Andric // weird to avoid tripping up the type traits in degenerate cases 674fe6060f1SDimitry Andric _Lazy<_And, 67581ad6265SDimitry Andric _Not<is_same<_Tp, _Up> >..., 67681ad6265SDimitry Andric _Not<is_convertible<_OtherTuple, _Tp> >..., 677cb14a3feSDimitry Andric _Not<is_constructible<_Tp, _OtherTuple> >... > > > {}; 6780b57cec5SDimitry Andric 679cb14a3feSDimitry Andric template <class... _Up, __enable_if_t< _And< _EnableCtorFromUTypesTuple<const tuple<_Up...>&> >::value, int> = 0> 680*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI 681*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> >::value) 682*0fca6ea1SDimitry Andric tuple(const tuple<_Up...>& __t) noexcept(_And<is_nothrow_constructible<_Tp, const _Up&>...>::value) 683cb14a3feSDimitry Andric : __base_(__t) {} 6840b57cec5SDimitry Andric 685cb14a3feSDimitry Andric template <class... _Up, 686cb14a3feSDimitry Andric class _Alloc, 687cb14a3feSDimitry Andric __enable_if_t< _And< _EnableCtorFromUTypesTuple<const tuple<_Up...>&> >::value, int> = 0> 688*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI 689*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<const _Up&, _Tp>...> >::value) 690cb14a3feSDimitry Andric tuple(allocator_arg_t, const _Alloc& __a, const tuple<_Up...>& __t) 691cb14a3feSDimitry Andric : __base_(allocator_arg_t(), __a, __t) {} 6920b57cec5SDimitry Andric 69306c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 69481ad6265SDimitry Andric // tuple(tuple<U...>&) constructors (including allocator_arg_t variants) 69581ad6265SDimitry Andric 696cb14a3feSDimitry Andric template <class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr> 697cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value) tuple(tuple<_Up...>& __t) 698cb14a3feSDimitry Andric : __base_(__t) {} 69981ad6265SDimitry Andric 700cb14a3feSDimitry Andric template <class _Alloc, class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<tuple<_Up...>&>::value>* = nullptr> 701cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<_Up&, _Tp>...>::value) 702cb14a3feSDimitry Andric tuple(allocator_arg_t, const _Alloc& __alloc, tuple<_Up...>& __t) 703cb14a3feSDimitry Andric : __base_(allocator_arg_t(), __alloc, __t) {} 70406c3fb27SDimitry Andric# endif // _LIBCPP_STD_VER >= 23 70581ad6265SDimitry Andric 706fe6060f1SDimitry Andric // tuple(tuple<U...>&&) constructors (including allocator_arg_t variants) 707cb14a3feSDimitry Andric template <class... _Up, __enable_if_t< _And< _EnableCtorFromUTypesTuple<tuple<_Up...>&&> >::value, int> = 0> 708cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value) 709*0fca6ea1SDimitry Andric tuple(tuple<_Up...>&& __t) noexcept(_And<is_nothrow_constructible<_Tp, _Up>...>::value) 710cb14a3feSDimitry Andric : __base_(std::move(__t)) {} 7110b57cec5SDimitry Andric 712cb14a3feSDimitry Andric template <class _Alloc, 713cb14a3feSDimitry Andric class... _Up, 714cb14a3feSDimitry Andric __enable_if_t< _And< _EnableCtorFromUTypesTuple<tuple<_Up...>&&> >::value, int> = 0> 715cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_Lazy<_And, is_convertible<_Up, _Tp>...> >::value) 716cb14a3feSDimitry Andric tuple(allocator_arg_t, const _Alloc& __a, tuple<_Up...>&& __t) 717cb14a3feSDimitry Andric : __base_(allocator_arg_t(), __a, std::move(__t)) {} 718fe6060f1SDimitry Andric 71906c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 72081ad6265SDimitry Andric // tuple(const tuple<U...>&&) constructors (including allocator_arg_t variants) 72181ad6265SDimitry Andric 722cb14a3feSDimitry Andric template <class... _Up, enable_if_t< _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr> 723cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value) 724cb14a3feSDimitry Andric tuple(const tuple<_Up...>&& __t) 725cb14a3feSDimitry Andric : __base_(std::move(__t)) {} 72681ad6265SDimitry Andric 727cb14a3feSDimitry Andric template <class _Alloc, 728cb14a3feSDimitry Andric class... _Up, 729cb14a3feSDimitry Andric enable_if_t< _EnableCtorFromUTypesTuple<const tuple<_Up...>&&>::value>* = nullptr> 730cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_Lazy<_And, is_convertible<const _Up&&, _Tp>...>::value) 73181ad6265SDimitry Andric tuple(allocator_arg_t, const _Alloc& __alloc, const tuple<_Up...>&& __t) 73281ad6265SDimitry Andric : __base_(allocator_arg_t(), __alloc, std::move(__t)) {} 73306c3fb27SDimitry Andric# endif // _LIBCPP_STD_VER >= 23 73481ad6265SDimitry Andric 735fe6060f1SDimitry Andric // tuple(const pair<U1, U2>&) constructors (including allocator_arg_t variants) 73681ad6265SDimitry Andric 737cb14a3feSDimitry Andric template <template <class...> class _Pred, 738cb14a3feSDimitry Andric class _Pair, 739cb14a3feSDimitry Andric class _DecayedPair = __remove_cvref_t<_Pair>, 740cb14a3feSDimitry Andric class _Tuple = tuple> 74181ad6265SDimitry Andric struct _CtorPredicateFromPair : false_type {}; 74281ad6265SDimitry Andric 74306c3fb27SDimitry Andric template <template <class...> class _Pred, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2> 744cb14a3feSDimitry Andric struct _CtorPredicateFromPair<_Pred, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > 745cb14a3feSDimitry Andric : _And< _Pred<_Tp1, __copy_cvref_t<_Pair, _Up1> >, _Pred<_Tp2, __copy_cvref_t<_Pair, _Up2> > > {}; 746fe6060f1SDimitry Andric 74781ad6265SDimitry Andric template <class _Pair> 74881ad6265SDimitry Andric struct _EnableCtorFromPair : _CtorPredicateFromPair<is_constructible, _Pair> {}; 74981ad6265SDimitry Andric 75081ad6265SDimitry Andric template <class _Pair> 75181ad6265SDimitry Andric struct _NothrowConstructibleFromPair : _CtorPredicateFromPair<is_nothrow_constructible, _Pair> {}; 75281ad6265SDimitry Andric 753bdd1243dSDimitry Andric template <class _Pair, class _DecayedPair = __remove_cvref_t<_Pair>, class _Tuple = tuple> 75481ad6265SDimitry Andric struct _BothImplicitlyConvertible : false_type {}; 75581ad6265SDimitry Andric 75681ad6265SDimitry Andric template <class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2> 757cb14a3feSDimitry Andric struct _BothImplicitlyConvertible<_Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > 758cb14a3feSDimitry Andric : _And< is_convertible<__copy_cvref_t<_Pair, _Up1>, _Tp1>, is_convertible<__copy_cvref_t<_Pair, _Up2>, _Tp2> > {}; 759fe6060f1SDimitry Andric 760cb14a3feSDimitry Andric template <class _Up1, 761cb14a3feSDimitry Andric class _Up2, 762cb14a3feSDimitry Andric template <class...> class _And = _And, 763cb14a3feSDimitry Andric __enable_if_t< _And< _EnableCtorFromPair<const pair<_Up1, _Up2>&> >::value, int> = 0> 764*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI 765*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> >::value) 766*0fca6ea1SDimitry Andric tuple(const pair<_Up1, _Up2>& __p) noexcept(_NothrowConstructibleFromPair<const pair<_Up1, _Up2>&>::value) 767cb14a3feSDimitry Andric : __base_(__p) {} 768fe6060f1SDimitry Andric 769cb14a3feSDimitry Andric template <class _Alloc, 770cb14a3feSDimitry Andric class _Up1, 771cb14a3feSDimitry Andric class _Up2, 772cb14a3feSDimitry Andric template <class...> class _And = _And, 773cb14a3feSDimitry Andric __enable_if_t< _And< _EnableCtorFromPair<const pair<_Up1, _Up2>&> >::value, int> = 0> 774*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI 775*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_BothImplicitlyConvertible<const pair<_Up1, _Up2>&> >::value) 776cb14a3feSDimitry Andric tuple(allocator_arg_t, const _Alloc& __a, const pair<_Up1, _Up2>& __p) 777cb14a3feSDimitry Andric : __base_(allocator_arg_t(), __a, __p) {} 778fe6060f1SDimitry Andric 77906c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 78081ad6265SDimitry Andric // tuple(pair<U1, U2>&) constructors (including allocator_arg_t variants) 781fe6060f1SDimitry Andric 782cb14a3feSDimitry Andric template <class _U1, class _U2, enable_if_t< _EnableCtorFromPair<pair<_U1, _U2>&>::value>* = nullptr> 783cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value) 784cb14a3feSDimitry Andric tuple(pair<_U1, _U2>& __p) 785cb14a3feSDimitry Andric : __base_(__p) {} 78681ad6265SDimitry Andric 787cb14a3feSDimitry Andric template <class _Alloc, 788cb14a3feSDimitry Andric class _U1, 789cb14a3feSDimitry Andric class _U2, 790cb14a3feSDimitry Andric enable_if_t< _EnableCtorFromPair<std::pair<_U1, _U2>&>::value>* = nullptr> 791cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<pair<_U1, _U2>&>::value) 792cb14a3feSDimitry Andric tuple(allocator_arg_t, const _Alloc& __alloc, pair<_U1, _U2>& __p) 793cb14a3feSDimitry Andric : __base_(allocator_arg_t(), __alloc, __p) {} 79481ad6265SDimitry Andric# endif 79581ad6265SDimitry Andric 79681ad6265SDimitry Andric // tuple(pair<U1, U2>&&) constructors (including allocator_arg_t variants) 797fe6060f1SDimitry Andric 798cb14a3feSDimitry Andric template <class _Up1, 799cb14a3feSDimitry Andric class _Up2, 800cb14a3feSDimitry Andric template <class...> class _And = _And, 801cb14a3feSDimitry Andric __enable_if_t< _And< _EnableCtorFromPair<pair<_Up1, _Up2>&&> >::value, int> = 0> 802*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI 803*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit(_Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> >::value) 804*0fca6ea1SDimitry Andric tuple(pair<_Up1, _Up2>&& __p) noexcept(_NothrowConstructibleFromPair<pair<_Up1, _Up2>&&>::value) 805cb14a3feSDimitry Andric : __base_(std::move(__p)) {} 806fe6060f1SDimitry Andric 807cb14a3feSDimitry Andric template <class _Alloc, 808cb14a3feSDimitry Andric class _Up1, 809cb14a3feSDimitry Andric class _Up2, 810cb14a3feSDimitry Andric template <class...> class _And = _And, 811cb14a3feSDimitry Andric __enable_if_t< _And< _EnableCtorFromPair<pair<_Up1, _Up2>&&> >::value, int> = 0> 812*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI 813*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit(_Not<_BothImplicitlyConvertible<pair<_Up1, _Up2>&&> >::value) 814cb14a3feSDimitry Andric tuple(allocator_arg_t, const _Alloc& __a, pair<_Up1, _Up2>&& __p) 815cb14a3feSDimitry Andric : __base_(allocator_arg_t(), __a, std::move(__p)) {} 816fe6060f1SDimitry Andric 81706c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 81881ad6265SDimitry Andric // tuple(const pair<U1, U2>&&) constructors (including allocator_arg_t variants) 81981ad6265SDimitry Andric 820cb14a3feSDimitry Andric template <class _U1, class _U2, enable_if_t< _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr> 821cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value) 822cb14a3feSDimitry Andric tuple(const pair<_U1, _U2>&& __p) 823cb14a3feSDimitry Andric : __base_(std::move(__p)) {} 82481ad6265SDimitry Andric 825cb14a3feSDimitry Andric template <class _Alloc, 826cb14a3feSDimitry Andric class _U1, 827cb14a3feSDimitry Andric class _U2, 828cb14a3feSDimitry Andric enable_if_t< _EnableCtorFromPair<const pair<_U1, _U2>&&>::value>* = nullptr> 829cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr explicit(!_BothImplicitlyConvertible<const pair<_U1, _U2>&&>::value) 83081ad6265SDimitry Andric tuple(allocator_arg_t, const _Alloc& __alloc, const pair<_U1, _U2>&& __p) 83181ad6265SDimitry Andric : __base_(allocator_arg_t(), __alloc, std::move(__p)) {} 83206c3fb27SDimitry Andric# endif // _LIBCPP_STD_VER >= 23 83381ad6265SDimitry Andric 834fe6060f1SDimitry Andric // [tuple.assign] 835cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& 836cb14a3feSDimitry Andric operator=(_If<_And<is_copy_assignable<_Tp>...>::value, tuple, __nat> const& __tuple) 837*0fca6ea1SDimitry Andric noexcept(_And<is_nothrow_copy_assignable<_Tp>...>::value) { 83881ad6265SDimitry Andric std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type()); 83981ad6265SDimitry Andric return *this; 84081ad6265SDimitry Andric } 84181ad6265SDimitry Andric 842cb14a3feSDimitry Andric# if _LIBCPP_STD_VER >= 23 843cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple const& __tuple) const 844cb14a3feSDimitry Andric requires(_And<is_copy_assignable<const _Tp>...>::value) 845cb14a3feSDimitry Andric { 846cb14a3feSDimitry Andric std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type()); 847cb14a3feSDimitry Andric return *this; 848cb14a3feSDimitry Andric } 849cb14a3feSDimitry Andric 850cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple&& __tuple) const 851cb14a3feSDimitry Andric requires(_And<is_assignable<const _Tp&, _Tp>...>::value) 852cb14a3feSDimitry Andric { 853cb14a3feSDimitry Andric std::__memberwise_forward_assign( 854cb14a3feSDimitry Andric *this, std::move(__tuple), __tuple_types<_Tp...>(), typename __make_tuple_indices<sizeof...(_Tp)>::type()); 85581ad6265SDimitry Andric return *this; 85681ad6265SDimitry Andric } 85706c3fb27SDimitry Andric# endif // _LIBCPP_STD_VER >= 23 85881ad6265SDimitry Andric 859cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& 860cb14a3feSDimitry Andric operator=(_If<_And<is_move_assignable<_Tp>...>::value, tuple, __nat>&& __tuple) 861*0fca6ea1SDimitry Andric noexcept(_And<is_nothrow_move_assignable<_Tp>...>::value) { 862cb14a3feSDimitry Andric std::__memberwise_forward_assign( 863cb14a3feSDimitry Andric *this, std::move(__tuple), __tuple_types<_Tp...>(), typename __make_tuple_indices<sizeof...(_Tp)>::type()); 8640b57cec5SDimitry Andric return *this; 8650b57cec5SDimitry Andric } 8660b57cec5SDimitry Andric 867cb14a3feSDimitry Andric template < 868cb14a3feSDimitry Andric class... _Up, 869cb14a3feSDimitry Andric __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, is_assignable<_Tp&, _Up const&>... >::value, 870cb14a3feSDimitry Andric int> = 0> 871cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(tuple<_Up...> const& __tuple) 872*0fca6ea1SDimitry Andric noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) { 873cb14a3feSDimitry Andric std::__memberwise_copy_assign(*this, __tuple, typename __make_tuple_indices<sizeof...(_Tp)>::type()); 8740b57cec5SDimitry Andric return *this; 8750b57cec5SDimitry Andric } 8760b57cec5SDimitry Andric 877cb14a3feSDimitry Andric template <class... _Up, 878cb14a3feSDimitry Andric __enable_if_t< _And< _BoolConstant<sizeof...(_Tp) == sizeof...(_Up)>, is_assignable<_Tp&, _Up>... >::value, 879cb14a3feSDimitry Andric int> = 0> 880cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(tuple<_Up...>&& __tuple) 881*0fca6ea1SDimitry Andric noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) { 882cb14a3feSDimitry Andric std::__memberwise_forward_assign( 883cb14a3feSDimitry Andric *this, std::move(__tuple), __tuple_types<_Up...>(), typename __make_tuple_indices<sizeof...(_Tp)>::type()); 884fe6060f1SDimitry Andric return *this; 885fe6060f1SDimitry Andric } 886fe6060f1SDimitry Andric 88706c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 888cb14a3feSDimitry Andric template <class... _UTypes, 889cb14a3feSDimitry Andric enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>, 89081ad6265SDimitry Andric is_assignable<const _Tp&, const _UTypes&>...>::value>* = nullptr> 891cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const tuple<_UTypes...>& __u) const { 892cb14a3feSDimitry Andric std::__memberwise_copy_assign(*this, __u, typename __make_tuple_indices<sizeof...(_Tp)>::type()); 89381ad6265SDimitry Andric return *this; 89481ad6265SDimitry Andric } 89581ad6265SDimitry Andric 896cb14a3feSDimitry Andric template <class... _UTypes, 897cb14a3feSDimitry Andric enable_if_t< _And<_BoolConstant<sizeof...(_Tp) == sizeof...(_UTypes)>, 89881ad6265SDimitry Andric is_assignable<const _Tp&, _UTypes>...>::value>* = nullptr> 899cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(tuple<_UTypes...>&& __u) const { 900cb14a3feSDimitry Andric std::__memberwise_forward_assign( 901cb14a3feSDimitry Andric *this, __u, __tuple_types<_UTypes...>(), typename __make_tuple_indices<sizeof...(_Tp)>::type()); 90281ad6265SDimitry Andric return *this; 90381ad6265SDimitry Andric } 90406c3fb27SDimitry Andric# endif // _LIBCPP_STD_VER >= 23 90581ad6265SDimitry Andric 906cb14a3feSDimitry Andric template <template <class...> class _Pred, 907cb14a3feSDimitry Andric bool _Const, 908cb14a3feSDimitry Andric class _Pair, 909cb14a3feSDimitry Andric class _DecayedPair = __remove_cvref_t<_Pair>, 910cb14a3feSDimitry Andric class _Tuple = tuple> 91181ad6265SDimitry Andric struct _AssignPredicateFromPair : false_type {}; 91281ad6265SDimitry Andric 913cb14a3feSDimitry Andric template <template <class...> class _Pred, bool _Const, class _Pair, class _Up1, class _Up2, class _Tp1, class _Tp2> 914cb14a3feSDimitry Andric struct _AssignPredicateFromPair<_Pred, _Const, _Pair, pair<_Up1, _Up2>, tuple<_Tp1, _Tp2> > 915cb14a3feSDimitry Andric : _And<_Pred<__maybe_const<_Const, _Tp1>&, __copy_cvref_t<_Pair, _Up1> >, 916cb14a3feSDimitry Andric _Pred<__maybe_const<_Const, _Tp2>&, __copy_cvref_t<_Pair, _Up2> > > {}; 91781ad6265SDimitry Andric 91881ad6265SDimitry Andric template <bool _Const, class _Pair> 91981ad6265SDimitry Andric struct _EnableAssignFromPair : _AssignPredicateFromPair<is_assignable, _Const, _Pair> {}; 92081ad6265SDimitry Andric 92181ad6265SDimitry Andric template <bool _Const, class _Pair> 92281ad6265SDimitry Andric struct _NothrowAssignFromPair : _AssignPredicateFromPair<is_nothrow_assignable, _Const, _Pair> {}; 92381ad6265SDimitry Andric 92406c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 925cb14a3feSDimitry Andric template <class _U1, class _U2, enable_if_t< _EnableAssignFromPair<true, const pair<_U1, _U2>&>::value>* = nullptr> 926cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(const pair<_U1, _U2>& __pair) const 92781ad6265SDimitry Andric noexcept(_NothrowAssignFromPair<true, const pair<_U1, _U2>&>::value) { 92881ad6265SDimitry Andric std::get<0>(*this) = __pair.first; 92981ad6265SDimitry Andric std::get<1>(*this) = __pair.second; 93081ad6265SDimitry Andric return *this; 93181ad6265SDimitry Andric } 93281ad6265SDimitry Andric 933cb14a3feSDimitry Andric template <class _U1, class _U2, enable_if_t< _EnableAssignFromPair<true, pair<_U1, _U2>&&>::value>* = nullptr> 934cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr const tuple& operator=(pair<_U1, _U2>&& __pair) const 93581ad6265SDimitry Andric noexcept(_NothrowAssignFromPair<true, pair<_U1, _U2>&&>::value) { 93681ad6265SDimitry Andric std::get<0>(*this) = std::move(__pair.first); 93781ad6265SDimitry Andric std::get<1>(*this) = std::move(__pair.second); 93881ad6265SDimitry Andric return *this; 93981ad6265SDimitry Andric } 94006c3fb27SDimitry Andric# endif // _LIBCPP_STD_VER >= 23 94181ad6265SDimitry Andric 942cb14a3feSDimitry Andric template <class _Up1, 943cb14a3feSDimitry Andric class _Up2, 944cb14a3feSDimitry Andric __enable_if_t< _EnableAssignFromPair<false, pair<_Up1, _Up2> const&>::value, int> = 0> 945cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(pair<_Up1, _Up2> const& __pair) 946*0fca6ea1SDimitry Andric noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2> const&>::value) { 9475f757f3fSDimitry Andric std::get<0>(*this) = __pair.first; 9485f757f3fSDimitry Andric std::get<1>(*this) = __pair.second; 949fe6060f1SDimitry Andric return *this; 950fe6060f1SDimitry Andric } 951fe6060f1SDimitry Andric 952cb14a3feSDimitry Andric template <class _Up1, class _Up2, __enable_if_t< _EnableAssignFromPair<false, pair<_Up1, _Up2>&&>::value, int> = 0> 953cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(pair<_Up1, _Up2>&& __pair) 954*0fca6ea1SDimitry Andric noexcept(_NothrowAssignFromPair<false, pair<_Up1, _Up2>&&>::value) { 9555f757f3fSDimitry Andric std::get<0>(*this) = std::forward<_Up1>(__pair.first); 9565f757f3fSDimitry Andric std::get<1>(*this) = std::forward<_Up2>(__pair.second); 957fe6060f1SDimitry Andric return *this; 958fe6060f1SDimitry Andric } 959fe6060f1SDimitry Andric 960fe6060f1SDimitry Andric // EXTENSION 961cb14a3feSDimitry Andric template < 962cb14a3feSDimitry Andric class _Up, 963cb14a3feSDimitry Andric size_t _Np, 964*0fca6ea1SDimitry Andric __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up const&>... >::value, int> = 0> 965cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(array<_Up, _Np> const& __array) 966*0fca6ea1SDimitry Andric noexcept(_And<is_nothrow_assignable<_Tp&, _Up const&>...>::value) { 967cb14a3feSDimitry Andric std::__memberwise_copy_assign(*this, __array, typename __make_tuple_indices<sizeof...(_Tp)>::type()); 968fe6060f1SDimitry Andric return *this; 969fe6060f1SDimitry Andric } 970fe6060f1SDimitry Andric 971fe6060f1SDimitry Andric // EXTENSION 972cb14a3feSDimitry Andric template <class _Up, 973cb14a3feSDimitry Andric size_t _Np, 974cb14a3feSDimitry Andric class = void, 975*0fca6ea1SDimitry Andric __enable_if_t< _And< _BoolConstant<_Np == sizeof...(_Tp)>, is_assignable<_Tp&, _Up>... >::value, int> = 0> 976cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple& operator=(array<_Up, _Np>&& __array) 977*0fca6ea1SDimitry Andric noexcept(_And<is_nothrow_assignable<_Tp&, _Up>...>::value) { 978cb14a3feSDimitry Andric std::__memberwise_forward_assign( 979cb14a3feSDimitry Andric *this, 980cb14a3feSDimitry Andric std::move(__array), 981fe6060f1SDimitry Andric __tuple_types<_If<true, _Up, _Tp>...>(), 982fe6060f1SDimitry Andric typename __make_tuple_indices<sizeof...(_Tp)>::type()); 983fe6060f1SDimitry Andric return *this; 984fe6060f1SDimitry Andric } 985fe6060f1SDimitry Andric 986fe6060f1SDimitry Andric // [tuple.swap] 987cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(tuple& __t) 988*0fca6ea1SDimitry Andric noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) { 989cb14a3feSDimitry Andric __base_.swap(__t.__base_); 990cb14a3feSDimitry Andric } 99181ad6265SDimitry Andric 99206c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 993cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple& __t) const 994cb14a3feSDimitry Andric noexcept(__all<is_nothrow_swappable_v<const _Tp&>...>::value) { 99581ad6265SDimitry Andric __base_.swap(__t.__base_); 99681ad6265SDimitry Andric } 99706c3fb27SDimitry Andric# endif // _LIBCPP_STD_VER >= 23 9980b57cec5SDimitry Andric}; 9990b57cec5SDimitry Andric 10000b57cec5SDimitry Andrictemplate <> 1001cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS tuple<> { 10020b57cec5SDimitry Andricpublic: 100306c3fb27SDimitry Andric constexpr tuple() _NOEXCEPT = default; 10040b57cec5SDimitry Andric template <class _Alloc> 1005cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {} 10060b57cec5SDimitry Andric template <class _Alloc> 1007cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {} 10080b57cec5SDimitry Andric template <class _Up> 1009cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(array<_Up, 0>) _NOEXCEPT {} 10100b57cec5SDimitry Andric template <class _Alloc, class _Up> 1011cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {} 1012cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(tuple&) _NOEXCEPT {} 101306c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 101481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {} 101581ad6265SDimitry Andric# endif 10160b57cec5SDimitry Andric}; 10170b57cec5SDimitry Andric 101806c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 101904eeddc0SDimitry Andrictemplate <class... _TTypes, class... _UTypes, template <class> class _TQual, template <class> class _UQual> 102004eeddc0SDimitry Andric requires requires { typename tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; } 102104eeddc0SDimitry Andricstruct basic_common_reference<tuple<_TTypes...>, tuple<_UTypes...>, _TQual, _UQual> { 102204eeddc0SDimitry Andric using type = tuple<common_reference_t<_TQual<_TTypes>, _UQual<_UTypes>>...>; 102304eeddc0SDimitry Andric}; 102404eeddc0SDimitry Andric 102504eeddc0SDimitry Andrictemplate <class... _TTypes, class... _UTypes> 102604eeddc0SDimitry Andric requires requires { typename tuple<common_type_t<_TTypes, _UTypes>...>; } 102704eeddc0SDimitry Andricstruct common_type<tuple<_TTypes...>, tuple<_UTypes...>> { 102804eeddc0SDimitry Andric using type = tuple<common_type_t<_TTypes, _UTypes>...>; 102904eeddc0SDimitry Andric}; 103006c3fb27SDimitry Andric# endif // _LIBCPP_STD_VER >= 23 103104eeddc0SDimitry Andric 103206c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 1033e40139ffSDimitry Andrictemplate <class... _Tp> 1034e40139ffSDimitry Andrictuple(_Tp...) -> tuple<_Tp...>; 1035e40139ffSDimitry Andrictemplate <class _Tp1, class _Tp2> 1036e40139ffSDimitry Andrictuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>; 1037e40139ffSDimitry Andrictemplate <class _Alloc, class... _Tp> 1038e40139ffSDimitry Andrictuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>; 1039e40139ffSDimitry Andrictemplate <class _Alloc, class _Tp1, class _Tp2> 1040e40139ffSDimitry Andrictuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>; 1041e40139ffSDimitry Andrictemplate <class _Alloc, class... _Tp> 1042e40139ffSDimitry Andrictuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>; 10430b57cec5SDimitry Andric# endif 10440b57cec5SDimitry Andric 1045*0fca6ea1SDimitry Andrictemplate <class... _Tp, __enable_if_t<__all<__is_swappable_v<_Tp>...>::value, int> = 0> 1046cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u) 1047*0fca6ea1SDimitry Andric noexcept(__all<__is_nothrow_swappable_v<_Tp>...>::value) { 1048cb14a3feSDimitry Andric __t.swap(__u); 1049cb14a3feSDimitry Andric} 10500b57cec5SDimitry Andric 105106c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 23 105281ad6265SDimitry Andrictemplate <class... _Tp> 1053cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr enable_if_t<__all<is_swappable_v<const _Tp>...>::value, void> 1054cb14a3feSDimitry Andricswap(const tuple<_Tp...>& __lhs, 1055cb14a3feSDimitry Andric const tuple<_Tp...>& __rhs) noexcept(__all<is_nothrow_swappable_v<const _Tp>...>::value) { 105681ad6265SDimitry Andric __lhs.swap(__rhs); 105781ad6265SDimitry Andric} 105881ad6265SDimitry Andric# endif 105981ad6265SDimitry Andric 10600b57cec5SDimitry Andric// get 10610b57cec5SDimitry Andric 10620b57cec5SDimitry Andrictemplate <size_t _Ip, class... _Tp> 1063cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, tuple<_Tp...> >::type& 1064cb14a3feSDimitry Andricget(tuple<_Tp...>& __t) _NOEXCEPT { 1065349cc55cSDimitry Andric typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type; 10660b57cec5SDimitry Andric return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get(); 10670b57cec5SDimitry Andric} 10680b57cec5SDimitry Andric 10690b57cec5SDimitry Andrictemplate <size_t _Ip, class... _Tp> 1070cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, tuple<_Tp...> >::type& 1071cb14a3feSDimitry Andricget(const tuple<_Tp...>& __t) _NOEXCEPT { 1072349cc55cSDimitry Andric typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type; 10730b57cec5SDimitry Andric return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get(); 10740b57cec5SDimitry Andric} 10750b57cec5SDimitry Andric 10760b57cec5SDimitry Andrictemplate <size_t _Ip, class... _Tp> 1077cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename tuple_element<_Ip, tuple<_Tp...> >::type&& 1078cb14a3feSDimitry Andricget(tuple<_Tp...>&& __t) _NOEXCEPT { 1079349cc55cSDimitry Andric typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type; 1080cb14a3feSDimitry Andric return static_cast<type&&>(static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get()); 10810b57cec5SDimitry Andric} 10820b57cec5SDimitry Andric 10830b57cec5SDimitry Andrictemplate <size_t _Ip, class... _Tp> 1084cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const typename tuple_element<_Ip, tuple<_Tp...> >::type&& 1085cb14a3feSDimitry Andricget(const tuple<_Tp...>&& __t) _NOEXCEPT { 1086349cc55cSDimitry Andric typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, tuple<_Tp...> >::type type; 1087cb14a3feSDimitry Andric return static_cast<const type&&>(static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get()); 10880b57cec5SDimitry Andric} 10890b57cec5SDimitry Andric 109006c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 14 10910b57cec5SDimitry Andric 10920b57cec5SDimitry Andrictemplate <class _T1, class... _Args> 1093cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr _T1& get(tuple<_Args...>& __tup) noexcept { 10945f757f3fSDimitry Andric return std::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); 10950b57cec5SDimitry Andric} 10960b57cec5SDimitry Andric 10970b57cec5SDimitry Andrictemplate <class _T1, class... _Args> 1098cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept { 10995f757f3fSDimitry Andric return std::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup); 11000b57cec5SDimitry Andric} 11010b57cec5SDimitry Andric 11020b57cec5SDimitry Andrictemplate <class _T1, class... _Args> 1103cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept { 11045f757f3fSDimitry Andric return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup)); 11050b57cec5SDimitry Andric} 11060b57cec5SDimitry Andric 11070b57cec5SDimitry Andrictemplate <class _T1, class... _Args> 1108cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept { 11095f757f3fSDimitry Andric return std::get<__find_exactly_one_t<_T1, _Args...>::value>(std::move(__tup)); 11100b57cec5SDimitry Andric} 11110b57cec5SDimitry Andric 11120b57cec5SDimitry Andric# endif 11130b57cec5SDimitry Andric 11140b57cec5SDimitry Andric// tie 11150b57cec5SDimitry Andric 11160b57cec5SDimitry Andrictemplate <class... _Tp> 1117cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<_Tp&...> tie(_Tp&... __t) _NOEXCEPT { 11180b57cec5SDimitry Andric return tuple<_Tp&...>(__t...); 11190b57cec5SDimitry Andric} 11200b57cec5SDimitry Andric 11210b57cec5SDimitry Andrictemplate <class... _Tp> 1122cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<typename __unwrap_ref_decay<_Tp>::type...> 1123cb14a3feSDimitry Andricmake_tuple(_Tp&&... __t) { 11245f757f3fSDimitry Andric return tuple<typename __unwrap_ref_decay<_Tp>::type...>(std::forward<_Tp>(__t)...); 11250b57cec5SDimitry Andric} 11260b57cec5SDimitry Andric 11270b57cec5SDimitry Andrictemplate <class... _Tp> 1128cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<_Tp&&...> forward_as_tuple(_Tp&&... __t) _NOEXCEPT { 11295f757f3fSDimitry Andric return tuple<_Tp&&...>(std::forward<_Tp>(__t)...); 11300b57cec5SDimitry Andric} 11310b57cec5SDimitry Andric 11320b57cec5SDimitry Andrictemplate <size_t _Ip> 1133cb14a3feSDimitry Andricstruct __tuple_equal { 11340b57cec5SDimitry Andric template <class _Tp, class _Up> 1135cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp& __x, const _Up& __y) { 11365f757f3fSDimitry Andric return __tuple_equal<_Ip - 1>()(__x, __y) && std::get<_Ip - 1>(__x) == std::get<_Ip - 1>(__y); 11370b57cec5SDimitry Andric } 11380b57cec5SDimitry Andric}; 11390b57cec5SDimitry Andric 11400b57cec5SDimitry Andrictemplate <> 1141cb14a3feSDimitry Andricstruct __tuple_equal<0> { 11420b57cec5SDimitry Andric template <class _Tp, class _Up> 1143cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp&, const _Up&) { 11440b57cec5SDimitry Andric return true; 11450b57cec5SDimitry Andric } 11460b57cec5SDimitry Andric}; 11470b57cec5SDimitry Andric 11480b57cec5SDimitry Andrictemplate <class... _Tp, class... _Up> 1149cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool 1150cb14a3feSDimitry Andricoperator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { 11510b57cec5SDimitry Andric static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes"); 11520b57cec5SDimitry Andric return __tuple_equal<sizeof...(_Tp)>()(__x, __y); 11530b57cec5SDimitry Andric} 11540b57cec5SDimitry Andric 115506c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 20 1156349cc55cSDimitry Andric 1157349cc55cSDimitry Andric// operator<=> 1158349cc55cSDimitry Andric 1159349cc55cSDimitry Andrictemplate <class... _Tp, class... _Up, size_t... _Is> 1160cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr auto 1161349cc55cSDimitry Andric__tuple_compare_three_way(const tuple<_Tp...>& __x, const tuple<_Up...>& __y, index_sequence<_Is...>) { 1162349cc55cSDimitry Andric common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> __result = strong_ordering::equal; 1163cb14a3feSDimitry Andric static_cast<void>( 1164cb14a3feSDimitry Andric ((__result = std::__synth_three_way(std::get<_Is>(__x), std::get<_Is>(__y)), __result != 0) || ...)); 1165349cc55cSDimitry Andric return __result; 1166349cc55cSDimitry Andric} 1167349cc55cSDimitry Andric 1168349cc55cSDimitry Andrictemplate <class... _Tp, class... _Up> 1169349cc55cSDimitry Andric requires(sizeof...(_Tp) == sizeof...(_Up)) 1170cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr common_comparison_category_t<__synth_three_way_result<_Tp, _Up>...> 1171cb14a3feSDimitry Andricoperator<=>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { 11725f757f3fSDimitry Andric return std::__tuple_compare_three_way(__x, __y, index_sequence_for<_Tp...>{}); 1173349cc55cSDimitry Andric} 1174349cc55cSDimitry Andric 117506c3fb27SDimitry Andric# else // _LIBCPP_STD_VER >= 20 1176349cc55cSDimitry Andric 11770b57cec5SDimitry Andrictemplate <class... _Tp, class... _Up> 1178cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool 1179cb14a3feSDimitry Andricoperator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { 11800b57cec5SDimitry Andric return !(__x == __y); 11810b57cec5SDimitry Andric} 11820b57cec5SDimitry Andric 11830b57cec5SDimitry Andrictemplate <size_t _Ip> 1184cb14a3feSDimitry Andricstruct __tuple_less { 11850b57cec5SDimitry Andric template <class _Tp, class _Up> 1186cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp& __x, const _Up& __y) { 11870b57cec5SDimitry Andric const size_t __idx = tuple_size<_Tp>::value - _Ip; 11885f757f3fSDimitry Andric if (std::get<__idx>(__x) < std::get<__idx>(__y)) 11890b57cec5SDimitry Andric return true; 11905f757f3fSDimitry Andric if (std::get<__idx>(__y) < std::get<__idx>(__x)) 11910b57cec5SDimitry Andric return false; 11920b57cec5SDimitry Andric return __tuple_less<_Ip - 1>()(__x, __y); 11930b57cec5SDimitry Andric } 11940b57cec5SDimitry Andric}; 11950b57cec5SDimitry Andric 11960b57cec5SDimitry Andrictemplate <> 1197cb14a3feSDimitry Andricstruct __tuple_less<0> { 11980b57cec5SDimitry Andric template <class _Tp, class _Up> 1199cb14a3feSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool operator()(const _Tp&, const _Up&) { 12000b57cec5SDimitry Andric return false; 12010b57cec5SDimitry Andric } 12020b57cec5SDimitry Andric}; 12030b57cec5SDimitry Andric 12040b57cec5SDimitry Andrictemplate <class... _Tp, class... _Up> 1205cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool 1206cb14a3feSDimitry Andricoperator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { 12070b57cec5SDimitry Andric static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes"); 12080b57cec5SDimitry Andric return __tuple_less<sizeof...(_Tp)>()(__x, __y); 12090b57cec5SDimitry Andric} 12100b57cec5SDimitry Andric 12110b57cec5SDimitry Andrictemplate <class... _Tp, class... _Up> 1212cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool 1213cb14a3feSDimitry Andricoperator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { 12140b57cec5SDimitry Andric return __y < __x; 12150b57cec5SDimitry Andric} 12160b57cec5SDimitry Andric 12170b57cec5SDimitry Andrictemplate <class... _Tp, class... _Up> 1218cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool 1219cb14a3feSDimitry Andricoperator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { 12200b57cec5SDimitry Andric return !(__x < __y); 12210b57cec5SDimitry Andric} 12220b57cec5SDimitry Andric 12230b57cec5SDimitry Andrictemplate <class... _Tp, class... _Up> 1224cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool 1225cb14a3feSDimitry Andricoperator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) { 12260b57cec5SDimitry Andric return !(__y < __x); 12270b57cec5SDimitry Andric} 12280b57cec5SDimitry Andric 122906c3fb27SDimitry Andric# endif // _LIBCPP_STD_VER >= 20 1230349cc55cSDimitry Andric 12310b57cec5SDimitry Andric// tuple_cat 12320b57cec5SDimitry Andric 1233cb14a3feSDimitry Andrictemplate <class _Tp, class _Up> 1234cb14a3feSDimitry Andricstruct __tuple_cat_type; 12350b57cec5SDimitry Andric 12360b57cec5SDimitry Andrictemplate <class... _Ttypes, class... _Utypes> 1237cb14a3feSDimitry Andricstruct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> > { 1238349cc55cSDimitry Andric typedef _LIBCPP_NODEBUG tuple<_Ttypes..., _Utypes...> type; 12390b57cec5SDimitry Andric}; 12400b57cec5SDimitry Andric 12410b57cec5SDimitry Andrictemplate <class _ResultTuple, bool _Is_Tuple0TupleLike, class... _Tuples> 1242cb14a3feSDimitry Andricstruct __tuple_cat_return_1 {}; 12430b57cec5SDimitry Andric 12440b57cec5SDimitry Andrictemplate <class... _Types, class _Tuple0> 1245cb14a3feSDimitry Andricstruct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0> { 1246cb14a3feSDimitry Andric using type _LIBCPP_NODEBUG = 1247cb14a3feSDimitry Andric typename __tuple_cat_type< tuple<_Types...>, 1248cb14a3feSDimitry Andric typename __make_tuple_types<__remove_cvref_t<_Tuple0> >::type >::type; 12490b57cec5SDimitry Andric}; 12500b57cec5SDimitry Andric 12510b57cec5SDimitry Andrictemplate <class... _Types, class _Tuple0, class _Tuple1, class... _Tuples> 12520b57cec5SDimitry Andricstruct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...> 12530b57cec5SDimitry Andric : public __tuple_cat_return_1< 1254cb14a3feSDimitry Andric typename __tuple_cat_type< tuple<_Types...>, 1255cb14a3feSDimitry Andric typename __make_tuple_types<__remove_cvref_t<_Tuple0> >::type >::type, 1256bdd1243dSDimitry Andric __tuple_like_ext<__libcpp_remove_reference_t<_Tuple1> >::value, 1257cb14a3feSDimitry Andric _Tuple1, 1258cb14a3feSDimitry Andric _Tuples...> {}; 12590b57cec5SDimitry Andric 1260cb14a3feSDimitry Andrictemplate <class... _Tuples> 1261cb14a3feSDimitry Andricstruct __tuple_cat_return; 12620b57cec5SDimitry Andric 12630b57cec5SDimitry Andrictemplate <class _Tuple0, class... _Tuples> 12640b57cec5SDimitry Andricstruct __tuple_cat_return<_Tuple0, _Tuples...> 12650b57cec5SDimitry Andric : public __tuple_cat_return_1<tuple<>, 1266cb14a3feSDimitry Andric __tuple_like_ext<__libcpp_remove_reference_t<_Tuple0> >::value, 1267cb14a3feSDimitry Andric _Tuple0, 1268cb14a3feSDimitry Andric _Tuples...> {}; 12690b57cec5SDimitry Andric 12700b57cec5SDimitry Andrictemplate <> 1271cb14a3feSDimitry Andricstruct __tuple_cat_return<> { 1272349cc55cSDimitry Andric typedef _LIBCPP_NODEBUG tuple<> type; 12730b57cec5SDimitry Andric}; 12740b57cec5SDimitry Andric 1275cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<> tuple_cat() { return tuple<>(); } 12760b57cec5SDimitry Andric 12770b57cec5SDimitry Andrictemplate <class _Rp, class _Indices, class _Tuple0, class... _Tuples> 12780b57cec5SDimitry Andricstruct __tuple_cat_return_ref_imp; 12790b57cec5SDimitry Andric 12800b57cec5SDimitry Andrictemplate <class... _Types, size_t... _I0, class _Tuple0> 1281cb14a3feSDimitry Andricstruct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0> { 1282bdd1243dSDimitry Andric typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0; 1283*0fca6ea1SDimitry Andric typedef tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_I0, _T0>::type>&&...> type; 12840b57cec5SDimitry Andric}; 12850b57cec5SDimitry Andric 12860b57cec5SDimitry Andrictemplate <class... _Types, size_t... _I0, class _Tuple0, class _Tuple1, class... _Tuples> 1287cb14a3feSDimitry Andricstruct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0, _Tuple1, _Tuples...> 12880b57cec5SDimitry Andric : public __tuple_cat_return_ref_imp< 1289cb14a3feSDimitry Andric tuple<_Types..., 1290*0fca6ea1SDimitry Andric __copy_cvref_t<_Tuple0, typename tuple_element<_I0, __libcpp_remove_reference_t<_Tuple0>>::type>&&...>, 1291bdd1243dSDimitry Andric typename __make_tuple_indices<tuple_size<__libcpp_remove_reference_t<_Tuple1> >::value>::type, 1292cb14a3feSDimitry Andric _Tuple1, 1293cb14a3feSDimitry Andric _Tuples...> {}; 12940b57cec5SDimitry Andric 12950b57cec5SDimitry Andrictemplate <class _Tuple0, class... _Tuples> 12960b57cec5SDimitry Andricstruct __tuple_cat_return_ref 1297cb14a3feSDimitry Andric : public __tuple_cat_return_ref_imp< 1298cb14a3feSDimitry Andric tuple<>, 1299cb14a3feSDimitry Andric typename __make_tuple_indices< tuple_size<__libcpp_remove_reference_t<_Tuple0> >::value >::type, 1300cb14a3feSDimitry Andric _Tuple0, 1301cb14a3feSDimitry Andric _Tuples...> {}; 13020b57cec5SDimitry Andric 13030b57cec5SDimitry Andrictemplate <class _Types, class _I0, class _J0> 13040b57cec5SDimitry Andricstruct __tuple_cat; 13050b57cec5SDimitry Andric 13060b57cec5SDimitry Andrictemplate <class... _Types, size_t... _I0, size_t... _J0> 1307cb14a3feSDimitry Andricstruct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> > { 13080b57cec5SDimitry Andric template <class _Tuple0> 13095f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 13100b57cec5SDimitry Andric typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type 1311cb14a3feSDimitry Andric operator()(tuple<_Types...> __t, _Tuple0&& __t0) { 131281ad6265SDimitry Andric (void)__t; // avoid unused parameter warning on GCC when _I0 is empty 13135f757f3fSDimitry Andric return std::forward_as_tuple( 1314cb14a3feSDimitry Andric std::forward<_Types>(std::get<_I0>(__t))..., std::get<_J0>(std::forward<_Tuple0>(__t0))...); 13150b57cec5SDimitry Andric } 13160b57cec5SDimitry Andric 13170b57cec5SDimitry Andric template <class _Tuple0, class _Tuple1, class... _Tuples> 13185f757f3fSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 13190b57cec5SDimitry Andric typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type 1320cb14a3feSDimitry Andric operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&&... __tpls) { 132181ad6265SDimitry Andric (void)__t; // avoid unused parameter warning on GCC when _I0 is empty 1322bdd1243dSDimitry Andric typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0; 1323bdd1243dSDimitry Andric typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple1> _T1; 1324*0fca6ea1SDimitry Andric return __tuple_cat<tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_J0, _T0>::type>&&...>, 132506c3fb27SDimitry Andric typename __make_tuple_indices<sizeof...(_Types) + tuple_size<_T0>::value>::type, 1326480093f4SDimitry Andric typename __make_tuple_indices<tuple_size<_T1>::value>::type>()( 13275f757f3fSDimitry Andric std::forward_as_tuple( 1328cb14a3feSDimitry Andric std::forward<_Types>(std::get<_I0>(__t))..., std::get<_J0>(std::forward<_Tuple0>(__t0))...), 1329cb14a3feSDimitry Andric std::forward<_Tuple1>(__t1), 1330cb14a3feSDimitry Andric std::forward<_Tuples>(__tpls)...); 13310b57cec5SDimitry Andric } 13320b57cec5SDimitry Andric}; 13330b57cec5SDimitry Andric 13340b57cec5SDimitry Andrictemplate <class _Tuple0, class... _Tuples> 1335cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename __tuple_cat_return<_Tuple0, _Tuples...>::type 1336cb14a3feSDimitry Andrictuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) { 1337bdd1243dSDimitry Andric typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0; 1338cb14a3feSDimitry Andric return __tuple_cat<tuple<>, __tuple_indices<>, typename __make_tuple_indices<tuple_size<_T0>::value>::type>()( 1339cb14a3feSDimitry Andric tuple<>(), std::forward<_Tuple0>(__t0), std::forward<_Tuples>(__tpls)...); 13400b57cec5SDimitry Andric} 13410b57cec5SDimitry Andric 13420b57cec5SDimitry Andrictemplate <class... _Tp, class _Alloc> 1343cb14a3feSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc> : true_type {}; 13440b57cec5SDimitry Andric 134506c3fb27SDimitry Andric# if _LIBCPP_STD_VER >= 17 1346cb14a3feSDimitry Andric# define _LIBCPP_NOEXCEPT_RETURN(...) \ 1347cb14a3feSDimitry Andric noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; } 13480b57cec5SDimitry Andric 13491db9f3b2SDimitry Andric// The _LIBCPP_NOEXCEPT_RETURN macro breaks formatting. 13501db9f3b2SDimitry Andric// clang-format off 13510b57cec5SDimitry Andrictemplate <class _Fn, class _Tuple, size_t... _Id> 1352cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) 1353cb14a3feSDimitry Andric__apply_tuple_impl(_Fn&& __f, _Tuple&& __t, __tuple_indices<_Id...>) 1354cb14a3feSDimitry Andric _LIBCPP_NOEXCEPT_RETURN(std::__invoke(std::forward<_Fn>(__f), std::get<_Id>(std::forward<_Tuple>(__t))...)) 13550b57cec5SDimitry Andric 13560b57cec5SDimitry Andrictemplate <class _Fn, class _Tuple> 13571db9f3b2SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) apply(_Fn&& __f, _Tuple&& __t) 13581db9f3b2SDimitry Andric _LIBCPP_NOEXCEPT_RETURN(std::__apply_tuple_impl( 13591db9f3b2SDimitry Andric std::forward<_Fn>(__f), 1360cb14a3feSDimitry Andric std::forward<_Tuple>(__t), 1361cb14a3feSDimitry Andric typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})) 13620b57cec5SDimitry Andric 1363*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 20 13640b57cec5SDimitry Andrictemplate <class _Tp, class _Tuple, size_t... _Idx> 13651db9f3b2SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>) 1366*0fca6ea1SDimitry Andric noexcept(noexcept(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...))) 1367*0fca6ea1SDimitry Andric requires is_constructible_v<_Tp, decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...> { 1368*0fca6ea1SDimitry Andric return _Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...); 1369*0fca6ea1SDimitry Andric} 1370*0fca6ea1SDimitry Andric#else 1371*0fca6ea1SDimitry Andrictemplate <class _Tp, class _Tuple, size_t... _Idx> 1372*0fca6ea1SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>, 1373*0fca6ea1SDimitry Andric enable_if_t<is_constructible_v<_Tp, decltype(std::get<_Idx>(std::forward<_Tuple>(__t)))...>> * = nullptr) 1374cb14a3feSDimitry Andric _LIBCPP_NOEXCEPT_RETURN(_Tp(std::get<_Idx>(std::forward<_Tuple>(__t))...)) 1375*0fca6ea1SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 13760b57cec5SDimitry Andric 1377*0fca6ea1SDimitry Andrictemplate <class _Tp, class _Tuple, 1378*0fca6ea1SDimitry Andric class _Seq = typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type, class = void> 1379*0fca6ea1SDimitry Andricinline constexpr bool __can_make_from_tuple = false; 1380*0fca6ea1SDimitry Andric 1381*0fca6ea1SDimitry Andrictemplate <class _Tp, class _Tuple, size_t... _Idx> 1382*0fca6ea1SDimitry Andricinline constexpr bool __can_make_from_tuple<_Tp, _Tuple, __tuple_indices<_Idx...>, 1383*0fca6ea1SDimitry Andric enable_if_t<is_constructible_v<_Tp, decltype(std::get<_Idx>(std::declval<_Tuple>()))...>>> = true; 1384*0fca6ea1SDimitry Andric 1385*0fca6ea1SDimitry Andric// Based on LWG3528(https://wg21.link/LWG3528) and http://eel.is/c++draft/description#structure.requirements-9, 1386*0fca6ea1SDimitry Andric// the standard allows to impose requirements, we constraint std::make_from_tuple to make std::make_from_tuple 1387*0fca6ea1SDimitry Andric// SFINAE friendly and also avoid worse diagnostic messages. We still keep the constraints of std::__make_from_tuple_impl 1388*0fca6ea1SDimitry Andric// so that std::__make_from_tuple_impl will have the same advantages when used alone. 1389*0fca6ea1SDimitry Andric#if _LIBCPP_STD_VER >= 20 13900b57cec5SDimitry Andrictemplate <class _Tp, class _Tuple> 1391*0fca6ea1SDimitry Andric requires __can_make_from_tuple<_Tp, _Tuple> // strengthen 1392*0fca6ea1SDimitry Andric#else 1393*0fca6ea1SDimitry Andrictemplate <class _Tp, class _Tuple, class = enable_if_t<__can_make_from_tuple<_Tp, _Tuple>>> // strengthen 1394*0fca6ea1SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 13951db9f3b2SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI constexpr _Tp make_from_tuple(_Tuple&& __t) 13961db9f3b2SDimitry Andric _LIBCPP_NOEXCEPT_RETURN(std::__make_from_tuple_impl<_Tp>( 1397cb14a3feSDimitry Andric std::forward<_Tuple>(__t), typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})) 13980b57cec5SDimitry Andric# undef _LIBCPP_NOEXCEPT_RETURN 13990b57cec5SDimitry Andric 140006c3fb27SDimitry Andric# endif // _LIBCPP_STD_VER >= 17 14010b57cec5SDimitry Andric 14020b57cec5SDimitry Andric#endif // !defined(_LIBCPP_CXX03_LANG) 14030b57cec5SDimitry Andric 14040b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 14050b57cec5SDimitry Andric 140606c3fb27SDimitry Andric_LIBCPP_POP_MACROS 140706c3fb27SDimitry Andric 14081db9f3b2SDimitry Andric// clang-format on 14091db9f3b2SDimitry Andric 1410bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 1411bdd1243dSDimitry Andric# include <exception> 1412bdd1243dSDimitry Andric# include <iosfwd> 1413bdd1243dSDimitry Andric# include <new> 1414bdd1243dSDimitry Andric# include <type_traits> 1415bdd1243dSDimitry Andric# include <typeinfo> 1416bdd1243dSDimitry Andric# include <utility> 1417bdd1243dSDimitry Andric#endif 1418bdd1243dSDimitry Andric 14190b57cec5SDimitry Andric#endif // _LIBCPP_TUPLE 1420