From dd8a50d89d7eaa04ca9511109342e11ff990e1fb Mon Sep 17 00:00:00 2001 From: Toru Fukaya Date: Wed, 10 May 2023 15:31:22 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E3=83=86=E3=83=B3?= =?UTF-8?q?=E3=83=97=E3=83=AC=E3=83=BC=E3=83=88=E3=81=AE=E5=9E=8B=E6=8E=A8?= =?UTF-8?q?=E8=AB=96=E3=82=92=E5=9B=9E=E9=81=BF=E3=81=99=E3=82=8B=E4=BE=8B?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 元の記述ではクラステンプレートの型推論を回避出来ていなかったため修正した。 この修正は以下のpp.55--58を参考に記述した。 [Class Template Argument Deduction - A New Abstraction - Zhihao Yuan - CppCon 2017](https://github.com/CppCon/CppCon2017/raw/master/Presentations/Class%20Template%20Argument%20Deduction%20-%20A%20New%20Abstraction/Class%20Template%20Argument%20Deduction%20-%20A%20New%20Abstraction%20-%20Zhihao%20Yuan%20-%20CppCon%202017.pdf) --- lang/cpp17/type_deduction_for_class_templates.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lang/cpp17/type_deduction_for_class_templates.md b/lang/cpp17/type_deduction_for_class_templates.md index 6f5012924..0d71bf481 100644 --- a/lang/cpp17/type_deduction_for_class_templates.md +++ b/lang/cpp17/type_deduction_for_class_templates.md @@ -203,11 +203,17 @@ int main() ### クラステンプレートの型推論を回避する例 ```cpp +// C++20 で追加された std::type_identity と同じことをするクラス +template +struct identity { + using type = T; +}; + template struct X { - using T_ = T; + using T_ = typename identity::type; - // テンプレートパラメータを直接使用せず、型の別名を付けてから使用する。 + // テンプレートパラメータを直接使用せず、identityを介して使用する。 // これによって、テンプレート引数を明示的に指定させられる X(T_) {} };