[英]If Template arg is function pointer
If I have a template class 如果我有模板课
template <class T>
class foo
{ /**/ }
How will i find if T
is a function pointer? 我如何确定
T
是否为函数指针?
There is std::is_pointer
and std::is_function
but no is_function_pointer
有
std::is_pointer
和std::is_function
但没有is_function_pointer
Just remove the pointer and check if the result is a function. 只需删除指针并检查结果是否为函数。
Here is code sample: 这是代码示例:
#include <utility>
#include <iostream>
template<class T> constexpr bool foo() {
using T2 = std::remove_pointer_t<T>;
return std::is_function<T2>::value;
}
int main() {
std::cout << "Is function? " << foo<void (int)>()
<< "; is function pointer? " << foo<int (*)()>() << "\n";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.