作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
<type_traits>
中有这些:
is_pointer<>
is_function<>
is_member_function_pointer<>
但不是这个:
is_function_pointer<>
为什么会这样?
最佳答案
[meta.unary.cat] 中的特征旨在将每种类型归为一个类别。是void、integral、pointer等等。在这个层面上,pointer-to-function和pointer-to-int没有区别。并注意指向成员的指针不是指针。只不过是英文的谐音而已。
它的目的是每个类型都返回 true 到 [meta.unary.cat] 中的一个特征。在这种分类中,函数指针和标量指针都将在 is_pointer
下返回 true。
我会注意到我们没有实现我们的目标。 nullptr_t
逃避了我们的目标。但我们接近了。 Here是当前 type_traits 分类的图形表示。
更新:
这是一个具有正确输出的正确工作程序:
#include <iostream>
#include <type_traits>
typedef void (*fptr)();
typedef int* intptr;
int main()
{
std::cout << std::is_function<fptr>::value << '\n';
std::cout << std::is_pointer<fptr>::value << '\n';
std::cout << std::is_pointer<intptr>::value << '\n';
}
0
1
1
关于c++ - <type_traits> 的 is_function_pointer<>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6560590/
中有这些: is_pointer<> is_function<> is_member_function_pointer<> 但不是这个: is_function_pointer<> 为什么会这样? 最
我是一名优秀的程序员,十分优秀!