gpt4 book ai didi

c++ - 的 is_function_pointer<>

转载 作者:可可西里 更新时间:2023-11-01 15:47:55 24 4
gpt4 key购买 nike

<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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com