Skip to content

Commit

Permalink
C++23 : 「変数テンプレートの部分特殊化を許可」を追加 (close #1034)
Browse files Browse the repository at this point in the history
  • Loading branch information
faithandbrave committed Feb 16, 2024
1 parent 070dd0d commit d936b97
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion implementation-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
| P2029R4: [文字・文字列リテラル中の数値・ユニバーサルキャラクタのエスケープに関する問題解決](/lang/cpp23/numeric_and_universal_character_escapes_in_character_and_string_literals.md.nolink) | | - | - | - | - |
| P2362R3: [1ワイド文字に収まらないワイド文字リテラルを禁止する](/lang/cpp23/remove_non_encodable_wide_character_literals_and_multicharacter_wide_character_literals.md) | エンコード結果として`wchar_t`の大きさに収まらないワイド文字リテラルを禁止する | 13 | 14 | 2023.2 | - |
| P2071R2: [名前付きユニバーサルキャラクタ名](/lang/cpp23/named_universal_character_escapes.md) | 16進数のユニバーサルキャラクタだけでなく、その文字の名前を入力できるようにする | 13 | 15 | 2023.2 | - |
| P2096R2: [部分特殊化の汎用化仕様](/lang/cpp23/generalized_wording_for_partial_specializations.md.nolink) | 変数テンプレートの部分特殊化を許可するために部分特殊化の仕様を汎用化 | - | - | - | - |
| P2096R2: [変数テンプレートの部分特殊化を許可](/lang/cpp23/generalized_wording_for_partial_specializations.md) | 変数テンプレートの部分特殊化を許可するために部分特殊化の仕様を汎用化 | - | - | - | - |
| P2582R1: [継承コンストラクタからのクラステンプレート引数の推論](/lang/cpp23/class_template_argument_deduction_from_inherited.md) | 継承コンストラクタからもクラステンプレート引数を推論できるようにする | - | - | - | - |
| P1938R3: [`if consteval`](/lang/cpp23/if_consteval.md) | コンパイル時の文脈かどうかで分岐させる | 12 | 14 | - | - |
| P1401R5: [定数式の文脈での`bool`への縮小変換を許可](/lang/cpp23/narrowing_contextual_conversions_to_bool.md) | `if constexpr(flags & Flags::Exec)``static_assert(N);`を許可 | 9 | 13 | 2022.2 | - |
Expand Down
1 change: 1 addition & 0 deletions lang/cpp14/variable_templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ auto main() -> int
## 関連項目
- [C++11 `constexpr`](/lang/cpp11/constexpr.md)
- [C++17 変数テンプレートのデフォルトテンプレート引数を許可](/lang/cpp17/allow_default_template_arguments_of_variable_templates.md)
- [C++23 変数テンプレートの部分特殊化を許可](/lang/cpp23/generalized_wording_for_partial_specializations.md)

## 参照
- [N3651 Variable Templates (Revision 1)](http://open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3651.pdf)
Expand Down
2 changes: 1 addition & 1 deletion lang/cpp23.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ C++23とは、2023年中に改訂される予定の、C++バージョンの通

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


Expand Down
40 changes: 40 additions & 0 deletions lang/cpp23/generalized_wording_for_partial_specializations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 変数テンプレートの部分特殊化を許可
* cpp23[meta cpp]

## 概要
変数テンプレートの仕様として、部分特殊化の許可を意図したような仕様はあったが、部分特殊化の多くの仕様はクラステンプレートのみを対象にしていた。

C++23では部分特殊化の仕様を見直し、変数テンプレートの部分特殊化を明確に許可する。


##
```cpp example
#include <iostream>

template <class T>
constexpr T zero = 0;

template <class T>
constexpr T* zero<T*> = nullptr;

int main() {
int x = zero<int>;
int* y = zero<int*>;

std::cout << x << std::endl;
std::cout << y << std::endl;
}
```

### 出力例
```
0
(nil)
```

## 関連項目
- [C++14 変数テンプレート](/lang/cpp14/variable_templates.md)


## 参照
- [P2096R2 Generalized wording for partial specializations](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2096r2.html)

0 comments on commit d936b97

Please sign in to comment.