我有一个很长的模板函数声明:
template <typename T> void foo(lots ofargs, goin here, andeven more, ofthese arguments, they just, dont stop);
没有过载。我想明确地实例化它。我可以写(比如T
= int
):
template void foo<int>(lots ofargs, goin here, andeven more, ofthese arguments, they just, dont stop);
但我真的不想复制那个冗长的声明。我本来希望能够这样说:
template <typename T> using bar = decltype(foo<T>);
接着:
template bar<int>;
现在,第一行编译(GCC 4.9.3),但第二行没有。我可以让它以某种方式工作吗?或者我可以使用decltype()
其他方式来避免复制实例化的声明吗?
注意:我特意使用了一个示例,在该示例中,您不能仅从参数中推断出类型,因为我也想要任何解决方案来支持这种情况。