This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

117
cppdraft/tuple/helper.md Normal file
View File

@@ -0,0 +1,117 @@
[tuple.helper]
# 22 General utilities library [[utilities]](./#utilities)
## 22.4 Tuples [[tuple]](tuple#helper)
### 22.4.7 Tuple helper classes [tuple.helper]
[🔗](#lib:tuple_size,in_general)
`template<class T> struct tuple_size;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2761)
Except where specified otherwise,
all specializations of tuple_size meet the[*Cpp17UnaryTypeTrait*](meta.rqmts#:Cpp17UnaryTypeTrait "21.3.2Requirements[meta.rqmts]") requirements ([[meta.rqmts]](meta.rqmts "21.3.2Requirements")) with a
base characteristic of integral_constant<size_t, N> for some N[.](#1.sentence-1)
[🔗](#lib:tuple_size)
`template<class... Types>
struct tuple_size<tuple<Types...>> : integral_constant<size_t, sizeof...(Types)> { };
`
[🔗](#lib:tuple_element)
`template<size_t I, class... Types>
struct tuple_element<I, tuple<Types...>> {
using type = TI;
};
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2784)
*Mandates*: I < sizeof...(Types)[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2788)
*Type*: TI is the
type of the Ith element of Types,
where indexing is zero-based[.](#3.sentence-1)
[🔗](#lib:tuple_size_)
`template<class T> struct tuple_size<const T>;
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2801)
Let TS denote tuple_size<T> of the cv-unqualified type T[.](#4.sentence-1)
If the expression TS::value is well-formed
when treated as an [unevaluated operand](expr.context#def:unevaluated_operand "7.2.3Context dependence[expr.context]"), then
each specialization of the template meets the [*Cpp17UnaryTypeTrait*](meta.rqmts#:Cpp17UnaryTypeTrait "21.3.2Requirements[meta.rqmts]") requirements ([[meta.rqmts]](meta.rqmts "21.3.2Requirements"))
with a base characteristic ofintegral_constant<size_t, TS::value>
Otherwise, it has no member value[.](#4.sentence-3)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2812)
Access checking is performed as if in a context
unrelated to TS and T[.](#5.sentence-1)
Only the validity of the immediate context of the expression is considered[.](#5.sentence-2)
[*Note [1](#note-1)*:
The compilation of the expression can result in side effects
such as the instantiation of class template specializations and
function template specializations, the generation of implicitly-defined functions, and so on[.](#5.sentence-3)
Such side effects are not in the “immediate context” and
can result in the program being ill-formed[.](#5.sentence-4)
— *end note*]
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2824)
In addition to being available via inclusion of the [<tuple>](tuple.syn#header:%3ctuple%3e "22.4.2Header <tuple> synopsis[tuple.syn]") header,
the template is available
when any of the headers[<array>](array.syn#header:%3carray%3e "23.3.2Header <array> synopsis[array.syn]"),[<ranges>](ranges.syn#header:%3cranges%3e "25.2Header <ranges> synopsis[ranges.syn]"), or[<utility>](utility.syn#header:%3cutility%3e "22.2.1Header <utility> synopsis[utility.syn]") are included[.](#6.sentence-1)
[🔗](#lib:tuple_element_)
`template<size_t I, class T> struct tuple_element<I, const T>;
`
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2840)
Let TE denote tuple_element_t<I, T> of the cv-unqualified type T[.](#7.sentence-1)
Then
each specialization of the template meets the [*Cpp17TransformationTrait*](meta.rqmts#:Cpp17TransformationTrait "21.3.2Requirements[meta.rqmts]") requirements ([[meta.rqmts]](meta.rqmts "21.3.2Requirements"))
with a member typedef type that names the type add_const_t<TE>[.](#7.sentence-2)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L2845)
In addition to being available via inclusion of the [<tuple>](tuple.syn#header:%3ctuple%3e "22.4.2Header <tuple> synopsis[tuple.syn]") header,
the template is available
when any of the headers[<array>](array.syn#header:%3carray%3e "23.3.2Header <array> synopsis[array.syn]"),[<ranges>](ranges.syn#header:%3cranges%3e "25.2Header <ranges> synopsis[ranges.syn]"), or[<utility>](utility.syn#header:%3cutility%3e "22.2.1Header <utility> synopsis[utility.syn]") are included[.](#8.sentence-1)