GCC:函数包装器模板问题
GCC: Function wrapper template troubles
我正在GCC 5.3
尝试让一些函数包装器代码在clang
上正常工作。下面是一个归结的例子:
#include <iostream>
using namespace std;
template<class Sig, Sig F>
struct FunctionWrapper;
template<class Ret, class... Args, Ret (*Func)(Args...)>
struct FunctionWrapper<Ret(Args...), Func>
{
};
static int testFunc(int _a, int _b)
{
return _a + _b;
}
int main() {
FunctionWrapper<int(int, int), testFunc> wrapper;
return 0;
}
我在 gcc 上遇到的错误如下:
prog.cpp:9:46:错误:"Ret(Args ...)"不是模板非类型参数的有效类型 struct FunctionWrapper ^ prog.cpp: 在函数 'int main()' 中: prog.cpp:20:45:错误:"int(int, int)"不是模板非类型参数的有效类型 函数包装器包装器;
关于如何在clang
和gcc
上都做到这一点的任何想法?
谢谢!
我认为这是一个 gcc 错误。根据[temp.param]:
类型为"
T
数组"或函数类型为T
的非类型模板参数被调整为"指向T
的指针"类型。
将Ret(Args...)
作为模板非类型参数等效于将Ret(*)(Args...)
作为模板非类型参数。
请注意,gcc 确实 [正确] 编译了以下示例,该示例与您的原始版本基本相同:
static int testFunc(int _a, int _b)
{
return _a + _b;
}
template <int F(int, int)>
struct Foo { };
int main() {
Foo<testFunc> wrapper;
return 0;
}
<小时 />作为一种解决方法,两个编译器都允许简单地强制非类型参数为指针:
template<class Sig, Sig* F>
struct FunctionWrapper;
template<class Ret, class... Args, Ret (*Func)(Args...)>
struct FunctionWrapper<Ret(Args...), Func>
{ };
但我不认为这应该是必要的。
相关文章:
- 使用双包装器类进行位操作(C++、clang)修复性能下降问题
- 超级对撞机2D阵列:生成嵌套:包装/尺寸问题
- 使用 Swig 在成员中包装具有互斥锁的 C++ 类时出现问题
- 我的基于可变模板的包装器函数有什么问题?
- 尝试构造包装器测量函数调用时间时出现问题
- 使用带有 MEX 包装器的帮助程序 C 文件从 MATLAB 2016 调用C++代码时出现问题
- 包装 std::istream 时出现问题,移动后unique_ptr不为空
- Visual Studio:C++\CLI 包装程序集路径依赖性问题
- UE4包装错误:将问题与OpenSSL联系起来
- 为使用boost的预开发库构建c++包装器时未解决的外部问题
- 将C 类包装到Python的问题
- GCC:函数包装器模板问题
- 将问题包装在堆数据结构中
- 尝试实现 Windows API 包装器的事件处理程序时遇到问题
- 编译 TCL-DLL 包装器时出现的问题
- 何时会出现结构包装问题
- 线程包装器实现问题
- 包装和使用返回带有 SWIG (python) 的结构的函数时出现问题
- 包装类常量正确性问题
- 包装C++代码的问题