私の理解の範囲内では、このケースではtemplate
キーワードは不必要と思います。template
キーワード明示による悪影響はなく、C++コンパイラは単に無視します。
https://wandbox.org/permlink/5ocKsEpZOepinlMf
実際にtemplate
キーワードを消してみてもTensorflowのビルドが通る気がします(手元にビルド環境ないため未確認)
template関数の呼び出し側にtemplate
を書くのはどういう場合に必要なのでしょうか?
テンプレート定義中からの メンバ関数テンプレートの呼び出し において、同メンバ関数テンプレートを有する クラス型がテンプレートパラメータに依存 する場合に、明示的なtemplate
キーワードが必須となります。この用法は template限定子 と呼ばれることもあります。N3337(C++11)仕様では [temp.name]/p4 が該当します。現行最新N4659(C++17)仕様でも [temp.name]/p4 です。
コード例をC++仕様書から引用します。クラス型T
はテンプレートパラメータT
が指定されるるまで確定しない、つまり「テンプレートパラメータに依存」するケースとなっています。
C++
1struct X {
2 template<std::size_t> X* alloc();
3 template<std::size_t> static X* adjust();
4};
5template<class T> void f(T* p) {
6 T* p1 = p->alloc<200>(); // ill-formed: < means less than
7 T* p2 = p->template alloc<200>(); // OK: < starts template argument list
8 T::adjust<100>(); // ill-formed: < means less than
9 T::template adjust<100>(); // OK: < starts template argument list
10}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/05/09 00:40
2019/05/09 01:40
退会済みユーザー
2019/05/09 01:46