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 typeatomic_bool
corresponding to the specifiedatomic<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/