gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 16:21:27 27 4
gpt4 key购买 nike

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/

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