可变模板成员函数的部分专门化
Partial specialization of variadic template member function
当使用可变模板对成员函数进行模板化时,我很难对它们进行专门化。
下面的例子专门针对整个类,它运行良好:
template<typename... Args>
class C;
template<class T, typename... Args>
class C<T, Args...> { };
template<>
class C<> { };
int main() {
C<int, double> c{};
}
下面的一个没有,尽管它背后的想法与上面的完全相同:
class F {
template<typename... Args>
void f();
};
template<class T, typename... Args>
void F::f<T, Args...>() { }
int main() {
}
我收到以下错误,我不明白是什么原因造成的:
main.cpp:7:23: error: non-type partial specialization ‘f<T, Args ...>’ is not allowed
void F::f<T, Args...>() { }
^
main.cpp:7:6: error: prototype for ‘void F::f()’ does not match any in class ‘F’
void F::f<T, Args...>() { }
^
main.cpp:3:10: error: candidate is: template<class ... Args> void F::f()
void f();
^
在专门化函数模板时,是否存在一些我不知道的限制?
G++版本为:G++(Debian 5.2.1-23)5.2.1 20151028
编辑
顺便说一下,我从真实代码中得到的实际问题是:
non-class, non-variable partial specialization ‘executeCommand<T, Args ...>’ is not allowed
无论如何,简化的例子与真实的例子相似。我希望这些错误并非完全无关。
不能部分专门化函数模板;只允许显式专门化。
使用重载可以获得几乎相同的效果,特别是如果使用诸如标记调度之类的概念。
相关文章:
- 尝试根据类中 typedef 的存在来专门化模板函数
- 如何基于模板化类的基类专门化成员函数
- 专门化模板覆盖函数/避免对象切片
- 如何使用模板化类专门化模板化函数?
- 线程 std::调用未知类型,无法专门化函数错误
- 如何在编译时专门化大型模板函数中的小部分
- 模板函数,其中一个参数需要专门化,而另一个不需要
- 错误 C2893 无法专门化函数模板'unknown-type std::invoke(_Callable &&,_Types &&...)'
- 从 std 命名空间中专门化函数模板的想法有多糟糕?
- 使用decltype尾部返回类型专门化函数模板
- 为模板化派生类专门化函数模板
- C++模板-专门化函数
- 在单独的.cpp文件中专门化函数模板
- 创建专门化函数模板的最佳方法是什么?
- 用泛型返回类型专门化函数
- 可以将运行时确定的模板参数传递给专门化函数吗?
- 根据调用方/上下文专门化函数的行为
- 专门化函数从其他函数调用
- c++中专门化函数模板的语法
- c++对枚举的专门化函数