我想实例化一些带有较长参数列表的函数:
template<typename T> void foo(
T& t,
SomeType some_parameter,
AnotherType another_parameter,
EtcType yet_another_parameter,
AsYouCanTell this_is_a_very_long_signature);
实例化 foo
的简单方式是:
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>);
但由于某些原因,这并不起作用。我能以某种方式使其起作用吗?
template foo<int>(int&, SomeType, AnotherType, EtcType, AsYouCanTell);
。您可以通过使用类型别名进一步缩短类型名称。 - dyp