4.0 KiB
[tuple.creation]
22 General utilities library [utilities]
22.4 Tuples [tuple]
22.4.5 Tuple creation functions [tuple.creation]
template<class... TTypes> constexpr tuple<unwrap_ref_decay_t<TTypes>...> make_tuple(TTypes&&... t);
Returns: tuple<unwrap_ref_decay_t...>(std::forward(t)...).
[Example 1:
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(t)...).
template<class... TTypes> constexpr tuple<TTypes&...> tie(TTypes&... t) noexcept;
Returns: tuple<TTypes&...>(t...).
[Example 2:
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<[tuple-like](tuple.like#concept:tuple-like "22.4.3 Concept tuple-like [tuple.like]")... Tuples> constexpr tuple<CTypes...> tuple_cat(Tuples&&... tpls);
Let n be sizeof...(Tuples).
For every integer 0â¤i<n:
-
Let Ti be the ith type in Tuples.
-
Let Ui be remove_cvref_t.
-
Let tpi be the ith element in the function parameter pack tpls.
-
Let Si be tuple_size_v.
-
Let Eki be tuple_element_t<k, Ui>.
-
Let eki be get(std::forward(tpi)).
-
Let Elemsi be a pack of the types E0i,â¦,ESiâ1i.
-
Let elemsi be a pack of the expressions e0i,â¦,eSiâ1i.
The types in CTypes are equal to the ordered sequence of the expanded packs of typesElems0..., Elems1..., …, Elemsnâ1....
Let celems be the ordered sequence of the expanded packs of expressionselems0..., …, elemsnâ1....
Mandates: (is_constructible_v<CTypes, decltype(celems)> && ...) is true.
Returns: tuple<CTypes...>(celems...).