C++ 参考手册

位置:首页 > C++ 参考手册 >原子操作库 >std::atomic > std::atomic<T>::operator++,++(int),--,--(int)

T operator++() noexcept;
T operator++() volatile noexcept;
(1) (仅为 atomic<Integral> 模板特化的成员)
(C++11 起)
T* operator++() noexcept;
T* operator++() volatile noexcept;
(1) (仅为 atomic<T*> 模板特化的成员)
(C++11 起)
T operator++( int ) noexcept;
T operator++( int ) volatile noexcept;
(2) (仅为 atomic<Integral> 模板特化的成员)
(C++11 起)
T* operator++( int ) noexcept;
T* operator++( int ) volatile noexcept;
(2) (仅为 atomic<T*> 模板特化的成员)
(C++11 起)
T operator--() noexcept;
T operator--() volatile noexcept;
(3) (仅为 atomic<Integral> 模板特化的成员)
(C++11 起)
T* operator--() noexcept;
T* operator--() volatile noexcept;
(3) (仅为 atomic<T*> 模板特化的成员)
(C++11 起)
T operator--( int ) noexcept;
T operator--( int ) volatile noexcept;
(4) (仅为 atomic<Integral> 模板特化的成员)
(C++11 起)
T* operator--( int ) noexcept;
T* operator--( int ) volatile noexcept;
(4) (仅为 atomic<T*> 模板特化的成员)
(C++11 起)

原子地自增或自减当前值。操作为读-修改-写操作。

1) 进行原子前自增。等价于 fetch_add(1)+1
2) 进行原子后自增。等价于 fetch_add(1)
3) 进行原子前自减。等价于 fetch_sub(1)-1
4) 进行原子后自减。等价于 fetch_sub(1)

对于有符号整数 (Integral) 类型,算术定义为使用补码表示。无未定义结果。对于 T* 类型,结果可能为未定义地址,但这些操作不会另有未定义行为。

参数

(无)

返回值

1,3) 修改后的原子变量的值。正式地说, *this修改顺序中自增/自减值的结果立即前趋于此函数的效果。
2,4) 修改前的原子变量的值。正式地说, *this修改顺序中值立即前趋于此函数的效果。

注意

不同于大多数前自增和自减运算符,原子类型的前自增和自减运算符不返回被修改对象的引用。它们替而返回存储值的副本。

参阅

原子地将参数加到存储于原子对象的值,并返回先前保有的值
(公开成员函数)
原子地从存储于原子对象的值减去参数,并获得先前保有的值
(公开成员函数)
加、减,或与原子值进行逐位与、或、异或
(公开成员函数)