原子结构的统一初始化
Uniform initialization of an atomic struct?
struct S
{
int x;
int y;
};
std::atomic<S> asd{{1, 2}}; // what should this be? This doesn't work
编辑:{{1, 2}}
和({1, 2})
都在g++中工作,都不能在clang中工作。有解决clang的方法吗?
这是clang bug 18097。这里有一个讨论这个问题的长线程,这似乎是clang只支持atomic<T>
中T
的标量类型。c++ 11标准明确规定(§29.5/1)T
可以是任何平凡的可复制类型。
问题中显示的两种用法都应该匹配这个构造函数
constexpr atomic(T) noexcept;
我能想到的解决这个问题的唯一方法是默认构造atomic<S>
,然后使用atomic::store
初始化对象。
std::atomic<S> asd;
asd.store({1,2});
std::atomic<S> asd({1, 2});
std::atomic<S>
有一个接受S类型值的构造函数。由于这个构造函数,初始化列表{1,2}被隐式地转换为临时S。
相关文章:
- 初始化派生结构的基部分/意外打包派生结构字段以对齐基结构的间隙
- 在 CPP 中初始化 typedef 结构变量
- 初始化原子指针是原子的吗?如果初始化或内存分配引发,会发生什么情况?
- 如何声明一个 std::用不同值内联初始化的结构数组
- 初始化指向结构C 的指针
- 在汇总中初始化原子成员
- 无法汇总初始化类型结构的变量,其中包含在类模板中的位字段成员
- 如何将部分初始化的结构对象放入向量
- 为什么我不能像正常一样初始化 typedef 结构字符串或字符?
- 在编译时初始化一个C++结构,就像一个未知绑定的数组
- C 98如何在标题中初始化静态结构阵列
- 初始化指针结构 - 内存中的外观
- C :初始化成员结构的静态字段的正确方法
- 如何在C 类的初始化器列表中使用未命名结构初始化成员结构
- 在c++中初始化扩展结构
- 正在尝试初始化区域结构内的边缘结构.我该怎么做
- libevent:未初始化的结构指针
- 在定义时初始化模板结构
- 为什么VS2013不零初始化此结构?
- 一次初始化所有结构变量