Skip to content

Commit d936b97

Browse files
committed
C++23 : 「変数テンプレートの部分特殊化を許可」を追加 (close #1034)
1 parent 070dd0d commit d936b97

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

implementation-status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@
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) | エンコード結果として`wchar_t`の大きさに収まらないワイド文字リテラルを禁止する | 13 | 14 | 2023.2 | - |
265265
| P2071R2: [名前付きユニバーサルキャラクタ名](/lang/cpp23/named_universal_character_escapes.md) | 16進数のユニバーサルキャラクタだけでなく、その文字の名前を入力できるようにする | 13 | 15 | 2023.2 | - |
266-
| P2096R2: [部分特殊化の汎用化仕様](/lang/cpp23/generalized_wording_for_partial_specializations.md.nolink) | 変数テンプレートの部分特殊化を許可するために部分特殊化の仕様を汎用化 | - | - | - | - |
266+
| P2096R2: [変数テンプレートの部分特殊化を許可](/lang/cpp23/generalized_wording_for_partial_specializations.md) | 変数テンプレートの部分特殊化を許可するために部分特殊化の仕様を汎用化 | - | - | - | - |
267267
| P2582R1: [継承コンストラクタからのクラステンプレート引数の推論](/lang/cpp23/class_template_argument_deduction_from_inherited.md) | 継承コンストラクタからもクラステンプレート引数を推論できるようにする | - | - | - | - |
268268
| P1938R3: [`if consteval`](/lang/cpp23/if_consteval.md) | コンパイル時の文脈かどうかで分岐させる | 12 | 14 | - | - |
269269
| P1401R5: [定数式の文脈での`bool`への縮小変換を許可](/lang/cpp23/narrowing_contextual_conversions_to_bool.md) | `if constexpr(flags & Flags::Exec)``static_assert(N);`を許可 | 9 | 13 | 2022.2 | - |

lang/cpp14/variable_templates.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ auto main() -> int
123123
## 関連項目
124124
- [C++11 `constexpr`](/lang/cpp11/constexpr.md)
125125
- [C++17 変数テンプレートのデフォルトテンプレート引数を許可](/lang/cpp17/allow_default_template_arguments_of_variable_templates.md)
126+
- [C++23 変数テンプレートの部分特殊化を許可](/lang/cpp23/generalized_wording_for_partial_specializations.md)
126127

127128
## 参照
128129
- [N3651 Variable Templates (Revision 1)](http://open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3651.pdf)

lang/cpp23.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ C++23とは、2023年中に改訂される予定の、C++バージョンの通
5959

6060
| 言語機能 | 説明 |
6161
|----------|------|
62-
| [部分特殊化の汎用化仕様](cpp23/generalized_wording_for_partial_specializations.md.nolink) | 変数テンプレートの部分特殊化を許可するために部分特殊化の仕様を汎用化 |
62+
| [変数テンプレートの部分特殊化を許可](cpp23/generalized_wording_for_partial_specializations.md) | 変数テンプレートの部分特殊化を許可するために部分特殊化の仕様を汎用化 |
6363
| [継承コンストラクタからのクラステンプレート引数の推論](cpp23/class_template_argument_deduction_from_inherited.md) | 継承コンストラクタからもクラステンプレート引数を推論できるようにする |
6464

6565

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# 変数テンプレートの部分特殊化を許可
2+
* cpp23[meta cpp]
3+
4+
## 概要
5+
変数テンプレートの仕様として、部分特殊化の許可を意図したような仕様はあったが、部分特殊化の多くの仕様はクラステンプレートのみを対象にしていた。
6+
7+
C++23では部分特殊化の仕様を見直し、変数テンプレートの部分特殊化を明確に許可する。
8+
9+
10+
##
11+
```cpp example
12+
#include <iostream>
13+
14+
template <class T>
15+
constexpr T zero = 0;
16+
17+
template <class T>
18+
constexpr T* zero<T*> = nullptr;
19+
20+
int main() {
21+
int x = zero<int>;
22+
int* y = zero<int*>;
23+
24+
std::cout << x << std::endl;
25+
std::cout << y << std::endl;
26+
}
27+
```
28+
29+
### 出力例
30+
```
31+
0
32+
(nil)
33+
```
34+
35+
## 関連項目
36+
- [C++14 変数テンプレート](/lang/cpp14/variable_templates.md)
37+
38+
39+
## 参照
40+
- [P2096R2 Generalized wording for partial specializations](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2096r2.html)

0 commit comments

Comments
 (0)