Std::is_function不能将模板参数识别为函数
std::is_function does not recognize template argument as function
我将一个指向函数的指针传递给函数模板:
int f(int a) { return a+1; }
template<typename F>
void use(F f) {
static_assert(std::is_function<F>::value, "Function required");
}
int main() {
use(&f); // Plain f does not work either.
}
但是模板参数F
不能被is_function
识别为函数,静态断言失败。编译错误提示F
是指向函数的指针int(*)(int)
。为什么会这样呢?在这种情况下,我如何识别函数或指向函数的指针?
F
是指向函数的指针(无论您传递的是f
还是&f
)。所以移除指针:
std::is_function<typename std::remove_pointer<F>::type>::value
(std::is_function<std::function<FT>> == false
;-))
相关文章:
- 函数的函数无法识别输入参数
- 如果与 QProcess 一起传递,则无法识别参数
- 试图使用int []作为打字模板,编译器未识别函数最小的原型中的参数
- 函数对象无法识别它获得的参数(std::set<int>)
- char在参数中未识别
- getopt:不识别有效的命令行参数
- 模板类不会重新识别模板参数
- 如何识别模板参数参数是否是模板内结构中另一个类的实例?C++
- 将参数类为可选函数指针,但不能识别为函数
- 试图将字符串作为类的参数传递,但在C++中它被识别为字符数组
- OpenCV错误:cvGetMat中有错误的标志(参数或结构字段)(无法识别或不支持的数组类型)
- 基于对应分组参数的PCL 3D对象识别
- static_assert 无法将 const char* 模板参数识别为 constexpr:g++ 错误?
- 将标记识别为参数的 C++ 宏
- 如何让 DOxygen 使用和识别注释掉的参数名称
- GLFW 错误 - GLFWwindow* 未被识别为有效参数
- 如何识别.exe文件是否需要输入参数
- mpirun:无法识别的参数mca
- gcc-4.8(和4.9)未识别-std=c++11参数
- Std::is_function不能将模板参数识别为函数