- atomic[meta header]
- std[meta namespace]
- atomic_ref[meta class]
- function[meta id-type]
- cpp20[meta cpp]
explicit atomic_ref(T& obj); // (1) C++20
constexpr explicit atomic_ref(T& obj); // (1) C++26
atomic_ref(const atomic_ref& other) noexcept; // (2) C++20
constexpr atomic_ref(const atomic_ref& other) noexcept; // (2) C++26
explicit atomic_ref(T&&) = delete; // (3) C++26
template <class U>
constexpr atomic_ref(const atomic_ref<U>& other) noexcept; // (4) C++26- (1) :
objを参照して*thisにポインタとして保持する - (2) : コピーコンストラクタ。
otherが参照するオブジェクトを*thisもまた参照する - (3) : 一時オブジェクト(右辺値)を参照する
atomic_refが構築されるのを防ぐため、delete定義されている - (4) : 変換コンストラクタ。CV修飾のみが異なる
atomic_ref<U>から構築し、otherが参照するオブジェクトを*thisもまた参照する
- (4) :
TとUが類似の型 (similar type) であり、is_convertible_v<U*, T*>がtrueであること- 類似の型とは、CV修飾を除いて同じ型であることをいう。つまり
atomic_ref<int>からatomic_ref<const int>のように、CV修飾を加える方向にのみ変換できる
- 類似の型とは、CV修飾を除いて同じ型であることをいう。つまり
- 参照するオブジェクトがメンバ定数のアライメント値
required_alignmentにアライメントされていること
投げない
- (4) :
*thisは、otherが参照しているオブジェクトを参照する
- デフォルトコンストラクタは定義されない
#include <atomic>
int main()
{
int value = 3;
// valueを参照するatomic_refオブジェクトを構築
std::atomic_ref<int> a{value};
// コンストラクタの引数によって、
// クラステンプレートのテンプレート引数を推論 (<int>を省略)
std::atomic_ref b{value};
// cとbで同じ値 (value) を参照
std::atomic_ref c = b;
}#include <atomic>
#include <iostream>
int main()
{
int value = 3;
std::atomic_ref<int> a{value};
// 読み取り専用のatomic_ref<const int>へ変換する
std::atomic_ref<const int> b = a;
std::cout << b.load() << std::endl;
}3
- C++20
- Clang: 9.0 [mark noimpl]
- GCC: 10.1 [mark verified]
- Visual C++: ??
- LWG issue 3160.
atomic_ref() = delete;should be deleted - P3309R3
constexpr atomicandatomic_ref- C++26で
constexprに対応した
- C++26で
- LWG Issue 4472.
atomic_ref<const T>can be constructed from temporaries- C++26で、一時オブジェクト(右辺値)からの構築を禁止する
delete定義されたコンストラクタ (3) が追加された
- C++26で、一時オブジェクト(右辺値)からの構築を禁止する
- P3860R1 Proposed Resolution for NB Comment GB13-309
atomic_ref<T>is not convertible toatomic_ref<const T>- C++26で、CV修飾のみが異なる
atomic_refから構築する変換コンストラクタ (4) が追加された。C++26でCV修飾された型に対応した際 (P3323R1) に、この変換が考慮されていなかったことへの対応
- C++26で、CV修飾のみが異なる