tmp/tmpf1m9yg30/{from.md → to.md}
RENAMED
|
@@ -1,69 +1,65 @@
|
|
| 1 |
#### Element access <a id="tuple.elem">[[tuple.elem]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
template <size_t I, class... Types>
|
| 5 |
-
constexpr tuple_element_t<I, tuple<Types...>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
```
|
| 7 |
|
| 8 |
*Requires:* `I < sizeof...(Types)`. The program is ill-formed if `I` is
|
| 9 |
out of bounds.
|
| 10 |
|
| 11 |
*Returns:* A reference to the `I`th element of `t`, where indexing is
|
| 12 |
zero-based.
|
| 13 |
|
| 14 |
-
```
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
`
|
| 22 |
-
|
| 23 |
-
*Note:* if a `T` in `Types` is some reference type `X&`, the return type
|
| 24 |
-
is `X&`, not `X&&`. However, if the element type is a non-reference type
|
| 25 |
-
`T`, the return type is `T&&`.
|
| 26 |
-
|
| 27 |
-
``` cpp
|
| 28 |
-
template <size_t I, class... Types>
|
| 29 |
-
constexpr tuple_element_t<I, tuple<Types...> > const& get(const tuple<Types...>& t) noexcept;
|
| 30 |
-
```
|
| 31 |
-
|
| 32 |
-
*Requires:* `I < sizeof...(Types)`. The program is ill-formed if `I` is
|
| 33 |
-
out of bounds.
|
| 34 |
-
|
| 35 |
-
*Returns:* A const reference to the `I`th element of `t`, where indexing
|
| 36 |
-
is zero-based.
|
| 37 |
-
|
| 38 |
-
Constness is shallow. If a `T` in `Types` is some reference type `X&`,
|
| 39 |
-
the return type is `X&`, not `const X&`. However, if the element type is
|
| 40 |
-
non-reference type `T`, the return type is `const T&`. This is
|
| 41 |
-
consistent with how constness is defined to work for member variables of
|
| 42 |
-
reference type.
|
| 43 |
|
| 44 |
``` cpp
|
| 45 |
template <class T, class... Types>
|
| 46 |
constexpr T& get(tuple<Types...>& t) noexcept;
|
| 47 |
template <class T, class... Types>
|
| 48 |
constexpr T&& get(tuple<Types...>&& t) noexcept;
|
| 49 |
template <class T, class... Types>
|
| 50 |
constexpr const T& get(const tuple<Types...>& t) noexcept;
|
|
|
|
|
|
|
| 51 |
```
|
| 52 |
|
| 53 |
*Requires:* The type `T` occurs exactly once in `Types...`. Otherwise,
|
| 54 |
the program is ill-formed.
|
| 55 |
|
| 56 |
*Returns:* A reference to the element of `t` corresponding to the type
|
| 57 |
`T` in `Types...`.
|
| 58 |
|
|
|
|
|
|
|
| 59 |
``` cpp
|
| 60 |
const tuple<int, const int, double, double> t(1, 2, 3.4, 5.6);
|
| 61 |
const int& i1 = get<int>(t); // OK. Not ambiguous. i1 == 1
|
| 62 |
const int& i2 = get<const int>(t); // OK. Not ambiguous. i2 == 2
|
| 63 |
const double& d = get<double>(t); // ERROR. ill-formed
|
| 64 |
```
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
| 69 |
|
|
|
|
| 1 |
#### Element access <a id="tuple.elem">[[tuple.elem]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
template <size_t I, class... Types>
|
| 5 |
+
constexpr tuple_element_t<I, tuple<Types...>>&
|
| 6 |
+
get(tuple<Types...>& t) noexcept;
|
| 7 |
+
template <size_t I, class... Types>
|
| 8 |
+
constexpr tuple_element_t<I, tuple<Types...>>&&
|
| 9 |
+
get(tuple<Types...>&& t) noexcept; // Note A
|
| 10 |
+
template <size_t I, class... Types>
|
| 11 |
+
constexpr const tuple_element_t<I, tuple<Types...>>&
|
| 12 |
+
get(const tuple<Types...>& t) noexcept; // Note B
|
| 13 |
+
template <size_t I, class... Types>
|
| 14 |
+
constexpr const tuple_element_t<I, tuple<Types...>>&& get(const tuple<Types...>&& t) noexcept;
|
| 15 |
```
|
| 16 |
|
| 17 |
*Requires:* `I < sizeof...(Types)`. The program is ill-formed if `I` is
|
| 18 |
out of bounds.
|
| 19 |
|
| 20 |
*Returns:* A reference to the `I`th element of `t`, where indexing is
|
| 21 |
zero-based.
|
| 22 |
|
| 23 |
+
[*Note 1*: \[Note A\]If a `T` in `Types` is some reference type `X&`,
|
| 24 |
+
the return type is `X&`, not `X&&`. However, if the element type is a
|
| 25 |
+
non-reference type `T`, the return type is `T&&`. — *end note*]
|
| 26 |
+
|
| 27 |
+
[*Note 2*: \[Note B\]Constness is shallow. If a `T` in `Types` is some
|
| 28 |
+
reference type `X&`, the return type is `X&`, not `const X&`. However,
|
| 29 |
+
if the element type is a non-reference type `T`, the return type is
|
| 30 |
+
`const T&`. This is consistent with how constness is defined to work for
|
| 31 |
+
member variables of reference type. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
``` cpp
|
| 34 |
template <class T, class... Types>
|
| 35 |
constexpr T& get(tuple<Types...>& t) noexcept;
|
| 36 |
template <class T, class... Types>
|
| 37 |
constexpr T&& get(tuple<Types...>&& t) noexcept;
|
| 38 |
template <class T, class... Types>
|
| 39 |
constexpr const T& get(const tuple<Types...>& t) noexcept;
|
| 40 |
+
template <class T, class... Types>
|
| 41 |
+
constexpr const T&& get(const tuple<Types...>&& t) noexcept;
|
| 42 |
```
|
| 43 |
|
| 44 |
*Requires:* The type `T` occurs exactly once in `Types...`. Otherwise,
|
| 45 |
the program is ill-formed.
|
| 46 |
|
| 47 |
*Returns:* A reference to the element of `t` corresponding to the type
|
| 48 |
`T` in `Types...`.
|
| 49 |
|
| 50 |
+
[*Example 1*:
|
| 51 |
+
|
| 52 |
``` cpp
|
| 53 |
const tuple<int, const int, double, double> t(1, 2, 3.4, 5.6);
|
| 54 |
const int& i1 = get<int>(t); // OK. Not ambiguous. i1 == 1
|
| 55 |
const int& i2 = get<const int>(t); // OK. Not ambiguous. i2 == 2
|
| 56 |
const double& d = get<double>(t); // ERROR. ill-formed
|
| 57 |
```
|
| 58 |
|
| 59 |
+
— *end example*]
|
| 60 |
+
|
| 61 |
+
[*Note 1*: The reason `get` is a non-member function is that if this
|
| 62 |
+
functionality had been provided as a member function, code where the
|
| 63 |
+
type depended on a template parameter would have required using the
|
| 64 |
+
`template` keyword. — *end note*]
|
| 65 |
|