我想要實例我可以使用decltype(或類似的東西)進行顯式模板實例化而不簽名重複嗎?
template<typename T> void foo(
T& t,
SomeType some_parameter,
AnotherType another_parameter,
EtcType yet_another_parameter,
AsYouCanTell this_is_a_very_long_signature);
就是用長簽名的功能。現在,我知道如何做到這一點:
template void foo<int>(
int& t,
SomeType some_parameter,
AnotherType another_parameter,
EtcType yet_another_parameter,
AsYouCanTell this_is_a_very_long_signature);
但我必須複製簽名。另外,如果想要針對5種不同類型的特定實例 - 我可以複製5次嗎?無厘頭......
我想也許我可以寫
template decltype(foo<int>);
,但由於某種原因,這是行不通的。爲什麼?
他沒有試圖做任何這些事情。他正試圖顯式實例化這個模板。 – Puppy 2015-02-05 23:25:41
您不需要函數參數的名稱,順便說一下:'template foo(int&,SomeType,AnotherType,EtcType,AsYouCanTell);'。您可以使用類型別名進一步縮短類型名稱。 –
dyp
2015-02-05 23:26:16
我不知道你是否可以濫用C++ 14的變量模板來做到這一點:而不是顯式實例化函數模板,也許顯式實例化引用函數模板的變量模板可能就足夠了。可能的是,靜態數據成員和別名模板可以實現類似的功能,但我不確定這一點。 – dyp 2015-02-05 23:32:43