Files
2025-10-25 03:02:53 +03:00

147 lines
4.0 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[tuple.creation]
# 22 General utilities library [[utilities]](./#utilities)
## 22.4 Tuples [[tuple]](tuple#creation)
### 22.4.5 Tuple creation functions [tuple.creation]
[🔗](#lib:make_tuple)
`template<class... TTypes>
constexpr tuple<unwrap_ref_decay_t<TTypes>...> make_tuple(TTypes&&... t);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2579)
*Returns*: tuple<unwrap_ref_decay_t<TTypes>...>(std::forward<TTypes>(t)...)[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2583)
[*Example [1](#example-1)*:
int i; float j;
make_tuple(1, ref(i), cref(j)); creates a tuple of type tuple<int, int&, const float&>[.](#2.sentence-1)
— *end example*]
[🔗](#lib:forward_as_tuple)
`template<class... TTypes>
constexpr tuple<TTypes&&...> forward_as_tuple(TTypes&&... t) noexcept;
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2601)
*Effects*: Constructs a tuple of references to the arguments in t suitable
for forwarding as arguments to a function[.](#3.sentence-1)
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)[.](#3.sentence-2)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2609)
*Returns*: tuple<TTypes&&...>(std::forward<TTypes>(t)...)[.](#4.sentence-1)
[🔗](#lib:tie)
`template<class... TTypes>
constexpr tuple<TTypes&...> tie(TTypes&... t) noexcept;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2623)
*Returns*: tuple<TTypes&...>(t...)[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2627)
[*Example [2](#example-2)*:
tie functions allow one to create tuples that unpack
tuples into variables[.](#6.sentence-1)
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*]
[🔗](#lib:tuple_cat)
`template<[tuple-like](tuple.like#concept:tuple-like "22.4.3Concept tuple-like[tuple.like]")... Tuples>
constexpr tuple<CTypes...> tuple_cat(Tuples&&... tpls);
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2647)
Let n be sizeof...(Tuples)[.](#7.sentence-1)
For every integer 0≤i<n:
- [(7.1)](#7.1)
Let Ti be the ith type in Tuples[.](#7.1.sentence-1)
- [(7.2)](#7.2)
Let Ui be remove_cvref_t<Ti>[.](#7.2.sentence-1)
- [(7.3)](#7.3)
Let tpi be the ith element
in the function parameter pack tpls[.](#7.3.sentence-1)
- [(7.4)](#7.4)
Let Si be tuple_size_v<Ui>[.](#7.4.sentence-1)
- [(7.5)](#7.5)
Let Eki be tuple_element_t<k, Ui>[.](#7.5.sentence-1)
- [(7.6)](#7.6)
Let eki be get<k>(std::forward<Ti>(tpi))[.](#7.6.sentence-1)
- [(7.7)](#7.7)
Let Elemsi be a pack of the types E0i,…,ESi−1i[.](#7.7.sentence-1)
- [(7.8)](#7.8)
Let elemsi be a pack of the expressions e0i,…,eSi−1i[.](#7.8.sentence-1)
The types in CTypes are equal to the ordered sequence of
the expanded packs of typesElems0..., Elems1..., …, Elemsn−1...[.](#7.sentence-3)
Let celems be the ordered sequence of
the expanded packs of expressionselems0..., …, elemsn−1...[.](#7.sentence-4)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2676)
*Mandates*: (is_constructible_v<CTypes, decltype(celems)> && ...) is true[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2680)
*Returns*: tuple<CTypes...>(celems...)[.](#9.sentence-1)