[tuple.creation] (original) (raw)

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<TTypes>...>(std​::​forward<TTypes>(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<TTypes>(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++");

— _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 :

The types in CTypes are equal to the ordered sequence of the expanded packs of types..., ..., …, ....

Let celems be the ordered sequence of the expanded packs of expressions..., …, ....

Mandates: (is_constructible_v<CTypes, decltype(celems)> && ...) is true.

Returns: tuple<CTypes...>(celems...).