Files
cppdraft_translate/cppdraft/tuple/creation.md
2025-10-25 03:02:53 +03:00

4.0 KiB
Raw Blame History

[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);

1

#

Returns: tuple<unwrap_ref_decay_t...>(std::forward(t)...).

2

#

[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;

3

#

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).

4

#

Returns: tuple<TTypes&&...>(std::forward(t)...).

🔗

template<class... TTypes> constexpr tuple<TTypes&...> tie(TTypes&... t) noexcept;

5

#

Returns: tuple<TTypes&...>(t...).

6

#

[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.3Concept tuple-like[tuple.like]")... Tuples> constexpr tuple<CTypes...> tuple_cat(Tuples&&... tpls);

7

#

Let n be sizeof...(Tuples).

For every integer 0≤i<n:

  • (7.1)

    Let Ti be the ith type in Tuples.

  • (7.2)

    Let Ui be remove_cvref_t.

  • (7.3)

    Let tpi be the ith element in the function parameter pack tpls.

  • (7.4)

    Let Si be tuple_size_v.

  • (7.5)

    Let Eki be tuple_element_t<k, Ui>.

  • (7.6)

    Let eki be get(std::forward(tpi)).

  • (7.7)

    Let Elemsi be a pack of the types E0i,…,ESi−1i.

  • (7.8)

    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....

8

#

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

9

#

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