20 General utilities library [utilities]

20.5 Tuples [tuple]

20.5.3 Class template tuple [tuple.tuple]

20.5.3.4 Tuple creation functions [tuple.creation]

In the function descriptions that follow, the members of a template parameter pack XTypes are denoted by X for i in [0, sizeof...(XTypes)) in order, where indexing is zero-based.
template<class... TTypes> constexpr tuple<unwrap_ref_decay_t<TTypes>...> make_tuple(TTypes&&... t);
Returns: tuple<unwrap_­ref_­decay_­t<TTypes>...>(std​::​forward<TTypes>(t)...).
Example
:
int i; float j;
make_tuple(1, ref(i), cref(j))
creates a tuple of type tuple<int, int&, const float&>.
— end example
 ]
template<class... TTypes> constexpr tuple<TTypes&&...> forward_as_tuple(TTypes&&... t) noexcept;
Effects: Constructs a tuple of references to the arguments in t suitable for forwarding as arguments to a function.
Because the result may contain references to temporary objects, a program shall ensure that the return value of this function does not outlive any of its arguments (e.g., the program should typically not store the result in a named variable).
Returns: tuple<TTypes&&...>(std​::​forward<TTypes>(t)...).
template<class... TTypes> constexpr tuple<TTypes&...> tie(TTypes&... t) noexcept;
Returns: tuple<TTypes&...>(t...).
When an argument in t is ignore, assigning any value to the corresponding tuple element has no effect.
Example
:
tie functions allow one to create tuples that unpack tuples into variables.
ignore can be used for elements that are not needed:
int i; std::string s;
tie(i, ignore, s) = make_tuple(42, 3.14, "C++");
// i == 42, s == "C++"
— end example
 ]
template<class... Tuples> constexpr tuple<CTypes...> tuple_cat(Tuples&&... tpls);
In the following paragraphs, let be the type in Tuples, be remove_­reference_­t<T>, and be the parameter in the function parameter pack tpls, where all indexing is zero-based.
Requires: For all i, shall be the type tuple<...>, where is the (possibly empty) cv-qualifier-seq and is the template parameter pack representing the element types in .
Let be the type in .
For all the following requirements shall be met:
  • If is deduced as an lvalue reference type, then is_­constructible_­v<, &> == true, otherwise
  • is_­constructible_­v<, &&> == true.
Remarks: The types in CTypes shall be equal to the ordered sequence of the extended types ..., ..., , ..., where n is equal to sizeof...(Tuples).
Let ... be the ordered sequence of tuple elements of the resulting tuple object corresponding to the type sequence .
Returns: A tuple object constructed by initializing the type element in ... with
get<>(std::forward<>())
for each valid and each group in order.
Note
:
An implementation may support additional types in the template parameter pack Tuples that support the tuple-like protocol, such as pair and array.
— end note
 ]