Skip to content

Commit

Permalink
Merge pull request #1149 from toru-fukaya/fix-non-deducible-example
Browse files Browse the repository at this point in the history
クラステンプレートの型推論を回避する例を修正
  • Loading branch information
faithandbrave committed May 10, 2023
2 parents 68dea79 + dd8a50d commit 20f209c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lang/cpp17/type_deduction_for_class_templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,17 @@ int main()

### クラステンプレートの型推論を回避する例
```cpp
// C++20 で追加された std::type_identity と同じことをするクラス
template <class T>
struct identity {
using type = T;
};

template <class T>
struct X {
using T_ = T;
using T_ = typename identity<T>::type;

// テンプレートパラメータを直接使用せず、型の別名を付けてから使用する
// テンプレートパラメータを直接使用せず、identityを介して使用する
// これによって、テンプレート引数を明示的に指定させられる
X(T_) {}
};
Expand Down

0 comments on commit 20f209c

Please sign in to comment.