c++ - 为什么允许 std::atomic_{char,schar,etc.} typedef 是 std::atomic<T> 基类的类型定义,而不仅仅是 atomic<T>?

标签 c++ c++11 stl atomic c++-standard-library

C++11 [atomics.types.generic]p7:

There shall be named types corresponding to the integral specializations of atomic, as specified in Table 145, and a named type atomic_bool corresponding to the specified atomic<bool>. Each named type is a either typedef to the corresponding specialization or a base class of the corresponding specialization. If it is a base class, it shall support the same member functions as the corresponding specialization.

(强调)

std::atomic_char的理由是什么?不等于 std::atomic<char> ,等等所有其他类型?这带来了什么样的灵 active ,为什么有用?乍一看,我不明白为什么不需要将这些类型定义为 std::atomic<T>直接特化。

请注意 N2427哪个提议<atomic>说 typedef 完全是专门化的,而不可能是基类。

最佳答案

它可能存在,因为有人已经使用 std::atomic_* 类型作为基类实现了原子,并且对这种方法提示很多/提供了一个很好的论据。

MSVC建议这样的实现。

this据称

Remove the definional base-class relationship between atomic_.... named types and the corresponding specializations of the atomic template class. The base-class relationship is now implementation-dependent. This change ensures compatibility with C. Some member functions and operators, that were formerly inherited from the base class, must be hoisted from the named types to the specializations.

关于c++ - 为什么允许 std::atomic_{char,schar,etc.} typedef 是 std::atomic<T> 基类的类型定义,而不仅仅是 atomic<T>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16423702/

相关文章:

c++ - opencv 视频初始化崩溃

c++ - 具有多个 "indexes"的标准 C++ 数据结构

c++ - 如何使用 C++ 原子

c++ - 右值引用可以绑定(bind)到函数吗?

c++ - std::array<T, 0> 的目的是什么?

c++ - 为什么我不能在 `std::initializer_list` 中使用引用类型

c++ - 如何编译LLVM万花筒教程?

c++ - Linux - 从管道读取的子级接收发送到标准输出的调试消息

c++ - 我应该如何在恒定长度的 STL 样式数据结构中实现 max_size?

c++ - 在 C++ 中记录代码执行