pre-typedef'ing a variadic-function-pointer 参数
pre-typedef'ing a variadic-function-pointer argument
我有一个函数foo
,它以可变函数指针为参数。
我想在函数声明之前使用"using"来定义参数的类型。
template <typename ... vARGS>
using TFuncType = void(*)(vARGS ... V_args);
template <typename ... vARGS>
void foo(TFuncType<vARGS ...> funcptr) {}
void bar(int i) {}
int main() {
foo(&bar); // This line fails to compile.
}
这不会编译。错误(通过使用c++1z的clang(是:
/make/proj/test/variadic-funcparam-deduce2.cpp:39:5: error: no matching function for call to 'foo'
foo(&bar);
^~~
/make/proj/test/variadic-funcparam-deduce2.cpp:33:36: note: candidate template ignored: substitution failure [with vARGS = int]
template <typename ... vARGS> void foo(TFuncType<vARGS ...> funcptr) {}
为什么"int"替换失败?
如果我在foo((:中显式写入类型,我可以成功编译
template <typename ... vARGS>
void foo(void(*funcptr)(vARGS ... V_args)) {}
但是,即使明确指定模板参数,并使用预广播的TFuncType<int>
作为参数,我也无法使初始("使用"(版本发挥作用,即:
int main() {
TF_call<int> fptr = &bar; // This line is OK.
foo<int>(fptr);
}
有人知道上面是什么吗?
使用typedef'd("using"(变量和/或我缺少的函数指针有什么奇怪的地方吗?
我相信这可能与我从这个答案中复制的以下文本有关,该答案本身取自14.5.7[临时别名]第2段中的C++标准:
当模板id指代别名模板的专业化时,它等效于通过替换的类型id中的模板参数的模板参数别名模板[注意:永远不会推导出别名模板名称--结束语]
如果我正确地解释了这一点,那就意味着GCC接受代码实际上是不符合要求的。
相关文章:
- Variadic模板未编译
- variadic模板中的模板参数推导失败
- [temp.variadic]中关于包扩展实例化的措辞
- std::绑定variadic模板和自动返回类型
- is_same和variadic模板编译时错误无效转换
- 限制variadic模板类中的构造函数访问
- 如何制作像类一样的"variadic"向量
- 用于"runtime variadic template"的重载逗号运算符
- variadic函数模板:基于n编译时值在运行时间自动n输入
- variadic函数和折叠表达:试图在Visual Studio 2017中编译时致命误差
- variadic模板代码中的GCC VS MSVC编译误差
- 使用variadic模板和运行时索引构造iterator_range
- variadic宏来创建结构
- 将variadic模板功能转换为许多具体功能
- 将variadic函数作为参数的函数
- variadic模板折叠程序在GCC9中失败
- 类型检测:使用variadic参数正确实现计算平均值的函数
- 如何在variadic模板参数中找到所有类的对象
- 在variadic函数中调用SNPRINTF和VSNPRINTF
- 如何访问variadic模板函数中的参数