c++ - pointer_traits 为既不是 X<A, T...> 也没有提供成员 typedef element_type 的类型提供什么?

标签 c++ pointers c++11

下面的结果是什么?它是格式错误、未定义的行为还是定义良好且格式正确的行为?

struct A {};
std::pointer_traits<A> x;

我之所以问,是因为好奇想知道,也想知道任意类型是不是指针。我还想包括 shared_ptr 和 friend 。我想知道是否有类型特征(谓词),如果没有,我是否可以使用 pointer_traits 并检测是否声明了 element_type。

最佳答案

它表示从 20.6.3p1 开始格式错误,因为它没有 element_type并且不是类模板实例化

typedef see below element_type;

Type: Ptr::element_type if such a type exists; otherwise, T if Ptr is a class template instantiation of the form SomePointer<T, Args>, where Args is zero or more type arguments; otherwise, the specialization is ill-formed.

关于c++ - pointer_traits 为既不是 X<A, T...> 也没有提供成员 typedef element_type 的类型提供什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15349326/

相关文章:

c - (新手) strstr() 返回带有无符号参数的 null

安卓NDK : "fatal error: ' thread' file not found"

c++ - 为什么 std::is_move_constructible<S>::value == false 尽管 S move 构造很好?什么是正确的行为?

c++ - 从 C 样式数组到 std::array 的转换对于数组来说是完全安全的吗?

c++ - 这个锁 block 是如何工作的?

c++ - 已删除的指针仍然指向旧数据

c - 为什么整数隐式转换为指针?

c - 初始化结构数组 - C 代码错误

c++ - 将整数放入字符串

c++ - 并行填充 vector ,顺序不重要