Skip to content

Commit 7e3cbd4

Browse files
committed
C++23 : 「thisポインタをもつ必要のない演算子をstaticとして宣言できるようにする」を追加し関連ページを修正 (close #1029)
1 parent 8ba9fba commit 7e3cbd4

File tree

8 files changed

+174
-11
lines changed

8 files changed

+174
-11
lines changed

implementation-status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
| P0847R7: [自身のオブジェクトを明示的にパラメータとして指定する](/lang/cpp23/deducing_this.md.nolink) | メンバ関数が`*this`の型・オブジェクトをパラメータとしてとり、`*this`オブジェクトがconst/非const、左辺値/右辺値であるかをメンバ関数内で識別できるようにする | - | 18 | - | 2022 Update 2 (partial) |
259259
| P1847R4: [アクセス制御の異なるメンバ変数のレイアウトを宣言順に規定](/lang/cpp23/make_declaration_order_layout_mandated.md.nolink) | アクセス制御の異なるメンバ変数のレイアウトが実装によって異なっていたため仕様を規定 | Yes | Yes | - | 2022 |
260260
| P2128R6: [添字演算子の多次元サポート](/lang/cpp23/multidimensional_subscript_operator.nd.nolink) | `operator[](int x, int y, int z)`のように添字演算子のオーバーロードで複数のパラメータをとることを許可 | 12 | 15 | 2022.2 | - |
261-
| P1169R4: [`this`ポインタをもつ必要のない演算子を`static`として宣言できるようにする](/lang/cpp23/static_operator.md.nolink) | | 13 | 16 | 2023.2 | - |
261+
| P1169R4: [`this`ポインタをもつ必要のない演算子を`static`として宣言できるようにする](/lang/cpp23/static_operator.md) | 状態をもたないいくつかの演算子を`static`として宣言できるようにする | 13 | 16 | 2023.2 | - |
262262
| P2201R1: [異なる文字エンコーディングをもつ文字列リテラルの連結を不適格とする](/lang/cpp23/mixed_string_literal_concatenation.md.nolink) | `auto a = u8"" L"";`のような異なる文字エンコーディング同士での文字列リテラルを連結を禁止する | Yes | Yes | 2022.2 | Yes |
263263
| P2029R4: [文字・文字列リテラル中の数値・ユニバーサルキャラクタのエスケープに関する問題解決](/lang/cpp23/numeric_and_universal_character_escapes_in_character_and_string_literals.md.nolink) | | - | - | - | - |
264264
| P2362R3: [1ワイド文字に収まらないワイド文字リテラルを禁止する](/lang/cpp23/remove_non_encodable_wide_character_literals_and_multicharacter_wide_character_literals.md.nolink) | エンコード結果として`wchar_t`の大きさに収まらないワイド文字リテラルを禁止する | 13 | 14 | 2023.2 | - |

lang/cpp11/lambda_expressions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ for_each(array, array + 4, <&>(double d) ( sum += factor ∗ d ));
532532
- [C++20 ジェネリックラムダのテンプレート構文](/lang/cpp20/familiar_template_syntax_for_generic_lambdas.md)
533533
- [C++23 ラムダ式で()を省略できる条件を緩和](/lang/cpp23/down_with_lambda_parens.md)
534534
- [C++23 ラムダ式に対する属性](/lang/cpp23/attributes_on_lambda_expressions.md)
535+
- [C++23 `this`ポインタをもつ必要のない演算子を`static`として宣言できるようにする](/lang/cpp23/static_operator.md)
535536

536537

537538
## 参照

lang/cpp23.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ C++23とは、2023年中に改訂される予定の、C++バージョンの通
4242
| [自身のオブジェクトを明示的にパラメータとして指定する](cpp23/deducing_this.md.nolink) | メンバ関数が`*this`の型・オブジェクトをパラメータとしてとり、`*this`オブジェクトがconst/非const、左辺値/右辺値であるかをメンバ関数内で識別できるようにする |
4343
| [アクセス制御の異なるメンバ変数のレイアウトを宣言順に規定](cpp23/make_declaration_order_layout_mandated.md.nolink) | アクセス制御の異なるメンバ変数のレイアウトが実装によって異なっていたため仕様を規定 |
4444
| [添字演算子の多次元サポート](cpp23/multidimensional_subscript_operator.nd.nolink) | `operator[](int x, int y, int z)`のように添字演算子のオーバーロードで複数のパラメータをとることを許可 |
45-
| [`this`ポインタをもつ必要のない演算子を`static`として宣言できるようにする](cpp23/static_operator.md.nolink) | |
45+
| [`this`ポインタをもつ必要のない演算子を`static`として宣言できるようにする](cpp23/static_operator.md) | 状態をもたないいくつかの演算子を`static`として宣言できるようにする |
4646

4747

4848
### 文字列

lang/cpp23/down_with_lambda_parens.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
C++23では、ラムダ式のパラメータリストが空であれば、以下の要素を含む場合であってもパラメータリストの `()` を省略できる。
66

77
- `constexpr`
8+
- `static`
89
- `mutable`
910
- `consteval`
1011
- `noexcept`
@@ -25,6 +26,7 @@ auto f5 = [] constexpr mutable noexcept -> bool { return true; }; // C++23 OK
2526
2627
## 関連項目
2728
- [C++11 ラムダ式](/lang/cpp11/lambda_expressions.md)
29+
- [C++23 `this`ポインタをもつ必要のない演算子を`static`として宣言できるようにする](/lang/cpp23/static_operator.md)
2830
2931
3032
## 参照

lang/cpp23/static_operator.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# thisポインタをもつ必要のない演算子をstaticとして宣言できるようにする
2+
* cpp23[meta cpp]
3+
4+
## 概要
5+
以下の演算子が`this`ポインタを必要としない (状態をもたない) 場合、演算子オーバーロードを`static`として定義できる:
6+
7+
- `operator()` (関数呼び出し演算子)
8+
- `operator[]` (添字演算子)
9+
10+
またラムダ式においても同様に、`static`をつけられるようになる。`static`をつけた場合、以下のようになる:
11+
12+
- `mutable`を同時に指定することはできない
13+
- `const`メンバ関数ではなくなる
14+
15+
16+
##
17+
```cpp example
18+
#include <iostream>
19+
20+
struct F {
21+
static bool operator()(int x) {
22+
return x > 0;
23+
}
24+
};
25+
26+
int main()
27+
{
28+
std::cout << F::operator()(1) << std::endl;
29+
std::cout << F{}(1) << std::endl;
30+
31+
auto f1 = []() static { return 1; };
32+
std::cout << f1() << std::endl;
33+
}
34+
```
35+
36+
### 出力
37+
```
38+
1
39+
1
40+
1
41+
```
42+
43+
## 関連項目
44+
- [C++11 ラムダ式](/lang/cpp11/lambda_expressions.md)
45+
- [`std::function::`推論補助](/reference/functional/function/op_deduction_guide.md)
46+
47+
48+
## 参照
49+
- [P1169R4 `static operator()`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1169r4.html)
50+
- [P2589R0 `static operator[]`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2589r0.pdf)

reference/functional/function/op_deduction_guide.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,29 @@
77
```cpp
88
namespace std {
99
template <class R, class... ArgTypes>
10-
function(R(*)(ArgTypes...)) -> function<R(ArgTypes...)>; // (1)
10+
function(R(*)(ArgTypes...)) -> function<R(ArgTypes...)>; // (1) C++17
1111

1212
template <class F>
13-
function(F) -> function<Signature>; // (2)
13+
function(F) -> function<Signature>; // (2) C++17
1414
}
1515
```
1616
1717
## 概要
1818
`std::function`クラステンプレートの型推論補助。
1919
2020
- (1) : 関数ポインタからの推論
21-
- (2) : 関数オブジェクトからの推論。このオーバーロードは、関数呼び出し演算子がひとつだけオーバーロードされている場合に有効
21+
- (2) : 関数オブジェクトからシグニチャの推論。このオーバーロードは、関数呼び出し演算子がひとつだけオーバーロードされている場合に有効
2222
2323
24-
## 備考
25-
- (2) : 式`&F::operator()`が妥当な場合のみ、オーバーロード解決に参加する。関数呼び出し演算子が複数オーバーロードされていると、この方法では関数ポインタを取得できない。この式が妥当な場合、`decltype(&F::operator())`で関数ポインタのシグニチャを取得でき、`std::function`クラスのテンプレート引数に渡すシグニチャとして使用できる
26-
- このクラスの推論補助は、将来のバージョンで変更される可能性がある
24+
## テンプレートパラメータ制約
25+
- (2) :
26+
- `&F::operator()`は評価されないオペランドとして扱われ、以下のいずれかの場合に適格である:
27+
- C++17 :
28+
- `decltype(&F::operator())`は、型`G`があるとして、`R(G::*)(A...) cv &(opt) noexcept(opt)`形式もしくは`R(*)(G cv ref(opt), A...) noexcept(opt)`形式であること
29+
- C++26 :
30+
- `F::operator()`が非静的メンバ関数であり、`decltype(&F::operator())`は、型`G`があるとして、`R(G::*)(A...) cv &(opt) noexcept(opt)`形式もしくは`R(*)(G cv ref(opt), A...) noexcept(opt)`形式であること
31+
- `F::operator()`静的メンバ関数であり、`decltype(&F::operator())`は`R(*)(A...) noexcept(opt)`形式であること
32+
2733
2834
## 例
2935
```cpp example
@@ -72,7 +78,7 @@ int main()
7278

7379
## バージョン
7480
### 言語
75-
- C++17
81+
- C++20
7682

7783
### 処理系
7884
- [Clang](/implementation.md#clang):
@@ -82,8 +88,9 @@ int main()
8288

8389
## 関連項目
8490
- [C++17 クラステンプレートのテンプレート引数推論](/lang/cpp17/type_deduction_for_class_templates.md)
91+
- [C++23 `this`ポインタをもつ必要のない演算子を`static`として宣言できるようにする](/lang/cpp23/static_operator.md)
92+
- [C++23 自身のオブジェクトを明示的にパラメータとして指定する](/lang/cpp23/deducing_this.md.nolink)
8593

8694

8795
## 参照
88-
- [P0433R2 Toward a resolution of US7 and US14: Integrating template deduction for class templates into the standard library](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0433r2.html)
89-
96+
- [LWG issue 3117. Missing `packaged_task` deduction guides](https://wg21.cmeerw.net/lwg/issue3117)

reference/future/packaged_task.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ namespace std {
5858
| [`swap`](packaged_task/swap_free.md) | 2つの`packaged_task`オブジェクトを入れ替える | C++11 |
5959
6060
61+
## 推論補助
62+
63+
| 名前 | 説明 | 対応バージョン |
64+
|---------------------------------------------|------------------------------------|-------|
65+
| [`(deduction_guide)`](packaged_task/op_deduction_guide.md) | クラステンプレートの推論補助 | C++20 |
66+
67+
6168
## その他
6269
6370
| 名前 | 説明 | 対応バージョン |
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# 推論補助
2+
* future[meta header]
3+
* std[meta namespace]
4+
* packaged_task[meta class]
5+
* cpp20[meta cpp]
6+
7+
```cpp
8+
namespace std {
9+
template <class R, class... ArgTypes>
10+
packaged_task(R(*)(ArgTypes...))
11+
-> packaged_task<R(ArgTypes...)>; // (1) C++20
12+
13+
template <class F>
14+
packaged_task(F)
15+
-> packaged_task<Signature>; // (2) C++20
16+
}
17+
```
18+
19+
## 概要
20+
`std::packaged_task`クラステンプレートの型推論補助。
21+
22+
- (1) : 関数ポインタからの推論
23+
- (2) : 関数オブジェクトからシグニチャの推論。このオーバーロードは、関数呼び出し演算子がひとつだけオーバーロードされている場合に有効
24+
25+
26+
## テンプレートパラメータ制約
27+
- (2) :
28+
- `&F::operator()`は評価されないオペランドとして扱われ、以下のいずれかの場合に適格である:
29+
- C++17 :
30+
- `decltype(&F::operator())`は、型`G`があるとして、`R(G::*)(A...) cv &(opt) noexcept(opt)`形式であること
31+
- C++26 :
32+
- `F::operator()`が非静的メンバ関数であり、`decltype(&F::operator())`は、型`G`があるとして、`R(G::*)(A...) cv &(opt) noexcept(opt)`形式もしくは`R(*)(G cv ref(opt), A...) noexcept(opt)`形式であること
33+
- `F::operator()`静的メンバ関数であり、`decltype(&F::operator())`は`R(*)(A...) noexcept(opt)`形式であること
34+
35+
36+
## 例
37+
```cpp example
38+
#include <iostream>
39+
#include <future>
40+
41+
int foo(int, char) { return 0; }
42+
43+
struct Functor {
44+
int operator()(double) { return 1; }
45+
};
46+
47+
int main()
48+
{
49+
// (1)
50+
// 関数ポインタからの型推論
51+
std::packaged_task f{foo};
52+
f(1, '3');
53+
std::cout << f.get_future().get() << std::endl;
54+
55+
// (2)
56+
// 関数オブジェクトからの型推論。
57+
// 関数呼び出し演算子がひとつだけオーバーロードされていること
58+
std::packaged_task g{Functor{}};
59+
g(1.23);
60+
std::cout << g.get_future().get() << std::endl;
61+
62+
// (3)
63+
// ラムダ式からの型推論
64+
std::packaged_task h{[](int) { return 2; }};
65+
h(3);
66+
std::cout << h.get_future().get() << std::endl;
67+
}
68+
```
69+
70+
### 出力
71+
```
72+
0
73+
1
74+
2
75+
```
76+
77+
78+
## バージョン
79+
### 言語
80+
- C++20
81+
82+
### 処理系
83+
- [Clang](/implementation.md#clang): 18
84+
- [GCC](/implementation.md#gcc): 11
85+
- [Visual C++](/implementation.md#visual_cpp): ??
86+
87+
88+
## 関連項目
89+
- [C++17 クラステンプレートのテンプレート引数推論](/lang/cpp17/type_deduction_for_class_templates.md)
90+
- [C++23 `this`ポインタをもつ必要のない演算子を`static`として宣言できるようにする](/lang/cpp23/static_operator.md)
91+
- [C++23 自身のオブジェクトを明示的にパラメータとして指定する](/lang/cpp23/deducing_this.md.nolink)
92+
93+
94+
## 参照
95+
- [P0433R2 Toward a resolution of US7 and US14: Integrating template deduction for class templates into the standard library](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0433r2.html)
96+

0 commit comments

Comments
 (0)