更新时间:2023-11-09 08:48:52
基于@chris注释,我认为以下代码可以完成这项工作:
Based on @chris comment, I think the following code will do the job:
#if __has_cpp_attribute(__cpp_lib_atomic_value_initialization)
std::atomic_flag a { };
#else
std::atomic_flag a = ATOMIC_FLAG_INIT;
#endif
所需的宏在< memory>
,< atomic>
和< version>
头文件之一中定义.我当然不想写已经被弃用的东西(即允许使用,但由于某些原因而劝阻).
The required macros are defined in either one of <memory>
, <atomic>
, and <version>
header files. I certainly don't want to write something that is already deprecated (ie, the use is allowed, but discouraged for some reason).