引数のconst参照を持つ可変的なテンプレート関数を特化する方法はありますか?const参照を使用したVariadicテンプレートの特殊化
例:宣言const Test&
引数で関数fooを呼び出すとき
template<typename T, typename... Args>
T foo(Args... args) = delete;
template<> int foo(int a, const char* str, const Test& t) { .... } // Fails to compile
//template<> int foo(int a, const char* str, Test) { .... } // Ok
int main() {
auto i = foo<int>(10, "test string!", t);
return 0;
}
、コンパイラは削除された機能に特化した機能とフォールバックを見るために失敗します。
error: use of deleted function ‘T foo(Args ...) [with T = int; Args = {int, const char*, Test}]’
auto i = foo<int>(10, "test string!", t);
上記のコードのコンパイル引数からconst参照を削除しても問題ありません。私は間違って何をしていますか?
コードは、主テンプレートは、あなたの通話に推論テンプレート引数がint
、const char*
、およびTest
、ないconst Test&
あるため。これはhere
、私は完全に明示的なインスタンスを忘れてしまいました。ご回答有難うございます! – Bected