Skip to content

Commit 893d77e

Browse files
committed
C++23 : 「継承コンストラクタからのクラステンプレート引数の推論」を追加 (close #1035)
1 parent 256984f commit 893d77e

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

implementation-status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@
264264
| P2362R3: [1ワイド文字に収まらないワイド文字リテラルを禁止する](/lang/cpp23/remove_non_encodable_wide_character_literals_and_multicharacter_wide_character_literals.md) | エンコード結果として`wchar_t`の大きさに収まらないワイド文字リテラルを禁止する | 13 | 14 | 2023.2 | - |
265265
| P2071R2: [名前付きユニバーサルキャラクタ名](/lang/cpp23/named_universal_character_escapes.md) | 16進数のユニバーサルキャラクタだけでなく、その文字の名前を入力できるようにする | 13 | 15 | 2023.2 | - |
266266
| P2096R2: [部分特殊化の汎用化仕様](/lang/cpp23/generalized_wording_for_partial_specializations.md.nolink) | 変数テンプレートの部分特殊化を許可するために部分特殊化の仕様を汎用化 | - | - | - | - |
267-
| P2582R1: [継承コンストラクタからのクラステンプレート引数の推論](/lang/cpp23/class_template_argument_deduction_from_inherited.md.nolink) | | - | - | - | - |
267+
| P2582R1: [継承コンストラクタからのクラステンプレート引数の推論](/lang/cpp23/class_template_argument_deduction_from_inherited.md) | 継承コンストラクタからもクラステンプレート引数を推論できるようにする | - | - | - | - |
268268
| P1938R3: [`if consteval`](/lang/cpp23/if_consteval.md.nolink) | コンパイル時の文脈かどうかで分岐させる | 12 | 14 | - | - |
269269
| P1401R5: [定数式の文脈での`bool`への縮小変換を許可](/lang/cpp23/narrowing_contextual_conversions_to_bool.md.nolink) | `if constexpr(flags & Flags::Exec)``static_assert(N);`を許可 | 9 | 13 | 2022.2 | - |
270270
| P2242R3: [定数式内での非リテラル変数、静的変数・スレッドローカル変数およびgotoとラベルの存在を許可する](/lang/cpp23/non_literal_variables_in_constexpr_functions.md) | コンパイル時に評価されない限り、定数式内に静的変数・スレッドローカル変数およびgoto文とラベルを含むことを許可する | 12 | 15 | 2022.2 | - |

lang/cpp17/type_deduction_for_class_templates.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ int main()
283283
- `std::array`の推論補助からは、非トリビアルなコンストラクタを持たないクラステンプレートであっても、推論補助を定義できることがわかる。ただし、配列の要素型を推論するためには、推論しない場合とは違った制限が必要となる
284284
- [C++20 集成体クラステンプレートのテンプレート引数推論](/lang/cpp20/class_template_argument_deduction_for_aggregates.md)
285285
- [C++20 エイリアステンプレート経由でのクラステンプレートのテンプレート引数推論](/lang/cpp20/class_template_argument_deduction_for_alias_templates.md)
286+
- [C++23 継承コンストラクタからのクラステンプレート引数の推論](/lang/cpp23/class_template_argument_deduction_from_inherited.md)
286287

287288

288289
## 参照

lang/cpp23.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ C++23とは、2023年中に改訂される予定の、C++バージョンの通
6060
| 言語機能 | 説明 |
6161
|----------|------|
6262
| [部分特殊化の汎用化仕様](cpp23/generalized_wording_for_partial_specializations.md.nolink) | 変数テンプレートの部分特殊化を許可するために部分特殊化の仕様を汎用化 |
63-
| [継承コンストラクタからのクラステンプレート引数の推論](cpp23/class_template_argument_deduction_from_inherited.md.nolink) | |
63+
| [継承コンストラクタからのクラステンプレート引数の推論](cpp23/class_template_argument_deduction_from_inherited.md) | 継承コンストラクタからもクラステンプレート引数を推論できるようにする |
6464

6565

6666
### 定数式
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# 継承コンストラクタからのクラステンプレート引数の推論
2+
* cpp23[meta cpp]
3+
4+
## 概要
5+
C++23では、派生クラスで定義した継承コンストラクタからでも、クラステンプレート引数を推論できるようになる。
6+
7+
8+
基本的な例:
9+
10+
```cpp
11+
template <typename T>
12+
struct B {
13+
B(T);
14+
};
15+
16+
template <typename T>
17+
struct C : public B<T> {
18+
using B<T>::B;
19+
};
20+
21+
template <typename T>
22+
struct D : public B<T> {};
23+
24+
C c(42); // C++23:OK, C<int>に推論される
25+
D d(42); // エラー!推論失敗。推論補助が継承されていない
26+
27+
B(int) -> B<char>; // 推論補助を追加定義
28+
C c2(42); // OK。C<char>に推論される
29+
30+
template <typename T>
31+
struct E : public B<int> {
32+
using B<int>::B;
33+
};
34+
35+
E e(42); // エラー!推論失敗。Eのテンプレート引数を推論補助から推論できない
36+
```
37+
38+
39+
派生クラスもテンプレート引数をもつ場合:
40+
41+
```cpp
42+
template <typename T, typename U, typename V>
43+
struct F {
44+
F(T, U, V);
45+
};
46+
47+
template <typename T, typename U>
48+
struct G : F<U, T, int> {
49+
using G::F::F;
50+
};
51+
52+
G g(true, 'a', 1); // OK。G<char, bool>に推論される
53+
```
54+
55+
56+
## 関連項目
57+
- [C++11 継承コンストラクタ](/lang/cpp11/inheriting_constructors.md)
58+
- [C++17 クラステンプレートのテンプレート引数推論](/lang/cpp17/type_deduction_for_class_templates.md)
59+
60+
61+
## 参照
62+
- [P2582R1 Wording for class template argument deduction from inherited constructors](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2582r1.pdf)

0 commit comments

Comments
 (0)