19 General utilities library [utilities]

19.5 Tuples [tuple]

19.5.3 Class template tuple [tuple.tuple]

19.5.3.1 Construction [tuple.cnstr]

In the descriptions that follow, let i be in the range [0, sizeof...(Types)) in order, T be the type in Types, and U be the type in a template parameter pack named UTypes, where indexing is zero-based.
For each tuple constructor, an exception is thrown only if the construction of one of the types in Types throws an exception.
The defaulted move and copy constructor, respectively, of tuple shall be a constexpr function if and only if all required element-wise initializations for copy and move, respectively, would satisfy the requirements for a constexpr function.
The defaulted move and copy constructor of tuple<> shall be constexpr functions.
If is_­trivially_­destructible_­v<T> is true for all T, then the destructor of tuple is trivial.
explicit(see below) constexpr tuple();
Effects: Value-initializes each element.
Remarks: This constructor shall not participate in overload resolution unless is_­default_­constructible_­v<T> is true for all i.
[Note
:
This behavior can be implemented by a constructor template with default template arguments.
end note
]
The expression inside explicit evaluates to true if and only if T is not implicitly default-constructible for at least one i.
[Note
:
This behavior can be implemented with a trait that checks whether a const T& can be initialized with {}.
end note
]
explicit(see below) constexpr tuple(const Types&...);
Effects: Initializes each element with the value of the corresponding parameter.
Remarks: This constructor shall not participate in overload resolution unless sizeof...(Types) >= 1 and is_­copy_­constructible_­v<T> is true for all i.
The expression inside explicit is equivalent to:
!conjunction_v<is_convertible<const Types&, Types>...>
template<class... UTypes> explicit(see below) constexpr tuple(UTypes&&... u);
Effects: Initializes the elements in the tuple with the corresponding value in std​::​forward<UTypes>(u).
Remarks: This constructor shall not participate in overload resolution unless sizeof...(Types) == sizeof...(UTypes) and sizeof...(Types) >= 1 and is_­constructible_­v<T, U&&> is true for all i.
The expression inside explicit is equivalent to:
!conjunction_v<is_convertible<UTypes, Types>...>
tuple(const tuple& u) = default;
Requires: is_­copy_­constructible_­v<T> is true for all i.
Effects: Initializes each element of *this with the corresponding element of u.
tuple(tuple&& u) = default;
Requires: is_­move_­constructible_­v<T> is true for all i.
Effects: For all i, initializes the element of *this with std​::​forward<T>(get<i>(u)).
template<class... UTypes> explicit(see below) constexpr tuple(const tuple<UTypes...>& u);
Effects: Initializes each element of *this with the corresponding element of u.
Remarks: This constructor shall not participate in overload resolution unless
  • sizeof...(Types) == sizeof...(UTypes) and
  • is_­constructible_­v<T, const U&> is true for all i, and
  • either sizeof...(Types) != 1, or (when Types... expands to T and UTypes... expands to U) is_­convertible_­v<const tuple<U>&, T>, is_­constructible_­v<T, const tuple<U>&>, and is_­same_­v<T, U> are all false.
The expression inside explicit is equivalent to:
!conjunction_v<is_convertible<const UTypes&, Types>...>
template<class... UTypes> explicit(see below) constexpr tuple(tuple<UTypes...>&& u);
Effects: For all i, initializes the element of *this with std​::​forward<U>(get<i>(u)).
Remarks: This constructor shall not participate in overload resolution unless
  • sizeof...(Types) == sizeof...(UTypes), and
  • is_­constructible_­v<T, U&&> is true for all i, and
  • either sizeof...(Types) != 1, or (when Types... expands to T and UTypes... expands to U) is_­convertible_­v<tuple<U>, T>, is_­constructible_­v<T, tuple<U>>, and is_­same_­v<T, U> are all false.
The expression inside explicit is equivalent to:
!conjunction_v<is_convertible<UTypes, Types>...>
template<class U1, class U2> explicit(see below) constexpr tuple(const pair<U1, U2>& u);
Effects: Initializes the first element with u.first and the second element with u.second.
Remarks: This constructor shall not participate in overload resolution unless sizeof...(Types) == 2, is_­constructible_­v<T, const U1&> is true and is_­constructible_­v<T, const U2&> is true.
The expression inside explicit is equivalent to:
!is_convertible_v<const U1&, T> || !is_convertible_v<const U2&, T>
template<class U1, class U2> explicit(see below) constexpr tuple(pair<U1, U2>&& u);
Effects: Initializes the first element with std​::​forward<U1>(u.first) and the second element with std​::​forward<U2>(u.second).
Remarks: This constructor shall not participate in overload resolution unless sizeof...(Types) == 2, is_­constructible_­v<T, U1&&> is true and is_­constructible_­v<T, U2&&> is true.
The expression inside explicit is equivalent to:
!is_convertible_v<U1, T> || !is_convertible_v<U2, T>
template<class Alloc> tuple(allocator_arg_t, const Alloc& a); template<class Alloc> explicit(see below) tuple(allocator_arg_t, const Alloc& a, const Types&...); template<class Alloc, class... UTypes> explicit(see below) tuple(allocator_arg_t, const Alloc& a, UTypes&&...); template<class Alloc> tuple(allocator_arg_t, const Alloc& a, const tuple&); template<class Alloc> tuple(allocator_arg_t, const Alloc& a, tuple&&); template<class Alloc, class... UTypes> explicit(see below) tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&); template<class Alloc, class... UTypes> explicit(see below) tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&&); template<class Alloc, class U1, class U2> explicit(see below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&); template<class Alloc, class U1, class U2> explicit(see below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
Requires: Alloc shall satisfy the Cpp17Allocator requirements (Table 33).
Effects: Equivalent to the preceding constructors except that each element is constructed with uses-allocator construction.