7
7
``` cpp
8
8
namespace std {
9
9
template<class F, class Tuple>
10
- constexpr decltype(auto) apply(F&& f, Tuple&& t);
10
+ constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++20まで
11
+
12
+ template<class F, class Tuple>
13
+ constexpr decltype(auto) apply(F&& f, Tuple&& t) noexcept(see below); // C++23から
11
14
}
12
15
```
13
16
@@ -16,7 +19,7 @@ namespace std {
16
19
17
20
18
21
## 要件
19
- 適用先の関数は[`Callable`](/reference/concepts/Callable.md)要件を満たす([INVOKE](/reference/concepts/Invoke.md)操作が可能)。展開されるものは、 [`std::tuple`](../tuple.md)、[`std::array`](/reference/array/array.md)または[`std::pair`](/reference/utility/pair.md)のように、[`std::get`](/reference/array/array/get.md)と[`std::tuple_size`](/reference/array/array/tuple_size.md)をサポートする必要がある 。
22
+ 適用先の関数は[`Callable`](/reference/concepts/Callable.md)要件を満たす([INVOKE](/reference/concepts/Invoke.md)操作が可能)。展開される`Tuple`型は [`std::tuple`](../tuple.md)に限定されず 、[`std::array`](/reference/array/array.md)または[`std::pair`](/reference/utility/pair.md)のように、[`std::get`](/reference/array/array/get.md)と[`std::tuple_size`](/reference/array/array/tuple_size.md)をサポートする型であればよい 。
20
23
21
24
22
25
## 効果
@@ -28,6 +31,7 @@ constexpr decltype(auto) apply-impl(F&& f, Tuple&& t, std::index_sequence<I...>)
28
31
return std::invoke(std::forward<F>(f), std::get<I>(std::forward<Tuple>(t))...);
29
32
}
30
33
```
34
+ * std::get[ link tuple/get.md]
31
35
* std::index_sequence[ link /reference/utility/index_sequence.md]
32
36
* std::invoke[ link /reference/functional/invoke.md]
33
37
* std::forward[ link /reference/utility/forward.md]
@@ -38,11 +42,17 @@ constexpr decltype(auto) apply-impl(F&& f, Tuple&& t, std::index_sequence<I...>)
38
42
return apply-impl(std::forward<F>(f), std::forward<Tuple>(t),
39
43
std::make_index_sequence<std::tuple_size_v<std::remove_reference_t <Tuple>>>{});
40
44
```
45
+ * std::tuple_size_v[ link tuple_size.md]
41
46
* std::make_index_sequence[ link /reference/utility/make_index_sequence.md]
47
+ * std::forward[ link /reference/utility/forward.md]
42
48
* std::remove_reference_t[ link /reference/type_traits/remove_reference.md]
43
49
44
50
## 戻り値
45
- 適用した関数の戻り値である。
51
+ 適用した関数呼び出しの戻り値
52
+
53
+
54
+ ## 例外
55
+ C++23から : ` I ` をパラメータパック` 0, 1, ..., ( ` [ ` tuple_size_v ` ] ( tuple_size.md ) ` < ` [ ` remove_reference_t ` ] ( /reference/type_traits/remove_reference.md ) ` <Tuple>>-1) ` としたとき、例外指定の式は次と等価 : ` noexcept( ` [ ` invoke ` ] ( /reference/functional/invoke.md ) ` (std::forward<F>(f), get<I>(std::forward<Tuple>(t))...)) `
46
56
47
57
48
58
## 例
86
96
87
97
88
98
## 関連項目
89
- - [make_from_tuple](../tuple/ make_from_tuple.md)
99
+ - [` make_from_tuple`]( make_from_tuple.md)
90
100
- [`std::tuple`](../tuple.md)
91
101
- [INVOKE](/reference/concepts/Invoke.md)
92
102
98
108
- [P0220R0 Adopt Library Fundamentals TS for C++17](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0220r0.html)
99
109
- [P0220R1 Adopt Library Fundamentals V1 TS Components for C++17 (R1)](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0220r1.html)
100
110
- [C++1z タプルを展開して関数呼び出しするapply関数 - Faith and Brave - C++で遊ぼう](https://faithandbrave.hateblo.jp/entry/2016/08/18/184315)
111
+ - [P2517R1 Add a conditional `noexcept` specification to `std::apply`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2517r1.html)
112
+ - C++23から条件付きで`noexpcet`例外指定が行われる。
0 commit comments