std::atomic_ref<T>:: operator++,++ (int) ,--,-- (int)
From cppreference.net
<
cpp
|
atomic
|
atomic ref
C++
Concurrency support library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::atomic_ref
| Member functions | ||||
|
(C++26)
|
||||
|
Operations for arithmetic types
(except
bool
and pointer-to-object)
|
||||
|
Operations for integral types
(except
bool
and pointer-to-object)
|
||||
|
(C++26)
|
||||
|
(C++26)
|
||||
|
atomic_ref::operator++
atomic_ref::operator++(int)
atomic_ref::operator--
atomic_ref::operator--(int)
|
||||
|
Operations for integral types
(except
bool
)
|
||||
| Constants | ||||
|
仅当
T
为除
cv
bool
外的整型或对象指针类型时提供
|
||
|
value_type operator
++
(
)
const
noexcept
;
|
(1) | (C++20 起) |
|
value_type operator
++
(
int
)
const
noexcept
;
|
(2) | (C++20 起) |
|
value_type operator
--
(
)
const
noexcept
;
|
(3) | (C++20 起) |
|
value_type operator
--
(
int
)
const
noexcept
;
|
(4) | (C++20 起) |
以原子方式递增或递减引用对象的当前值。这些操作属于读-修改-写操作。
1)
执行原子前置递增。等价于
return
fetch_add
(
1
)
+
1
;
。
2)
执行原子后递增。等价于
return
fetch_add
(
1
)
;
。
3)
执行原子前置递减。等价于
return
fetch_sub
(
1
)
-
1
;
4)
执行原子后自减操作。等价于
return
fetch_sub
(
1
)
;
。
- 对于有符号整数类型,算术运算定义为使用二进制补码表示。不存在未定义结果。
- 对于指向对象类型的指针,结果可能是一个未定义的地址,但该操作本身没有未定义行为。如果 std:: remove_pointer_t < T > 不是完整对象类型,则程序非良构。
这些重载仅当 std:: is_const_v < T > 为 false 时参与重载决议。
目录 |
返回值
1,3)
修改后引用对象的值。
2,4)
被引用对象在修改前的值。
注释
与大多数前置递增和前置递减运算符不同,
atomic_ref
的前置递增和前置递减运算符不会返回对修改后对象的引用,而是返回存储值的副本。
缺陷报告
下列行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。
| 缺陷报告 | 适用范围 | 发布时的行为 | 正确行为 |
|---|---|---|---|
|
LWG 3508
( P3323R1 ) |
C++20 | 递增和递减运算符对 const T 无意义 |
约束为仅接受非 const 的
T
|
参见
|
以原子方式将参数加到引用对象中存储的值,并获取先前持有的值
(公开成员函数) |
|
|
以原子方式从引用对象中存储的值减去参数,并获取先前持有的值
(公开成员函数) |
|
|
以原子方式对引用值进行加法或减法运算
(公开成员函数) |
|
|
以原子方式对引用值执行按位与、或、异或运算
(公开成员函数) |