【发布时间】:2016-04-11 20:45:33
【问题描述】:
我有一个很长的模板函数声明:
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() 其他方式来避免复制实例化声明吗?
注意:我特意使用了一个示例,在该示例中,您不能仅从参数中推断出类型,因为我也需要任何解决方案来支持这种情况。
【问题讨论】:
标签: c++ templates code-duplication decltype explicit-instantiation