在线文档教程
C++

std::atomic::operators (int)

STd::原子::运算符++,++%28 int%29,-,-%28 int%29

T operator++( T operator++() volatile;(1)(member only of atomic template specialization)(since C++11)
T* operator++( T* operator++() volatile;(1)(member only of atomic<T*> template specialization)(since C++11)
T operator++( int T operator++( int ) volatile;(2)(member only of atomic<Integral> template specialization)(since C++11)
T* operator++( int T* operator++( int ) volatile;(2)(member only of atomic<T*> template specialization)(since C++11)
T operator--( T operator--() volatile;(3)(member only of atomic<Integral> template specialization)(since C++11)
T* operator--( T* operator--() volatile;(3)(member only of atomic<T*> template specialization)(since C++11)
T operator--( int T operator--( int ) volatile;(4)(member only of atomic<Integral> template specialization)(since C++11)
T* operator--( int T* operator--( int ) volatile;(4)(member only of atomic<T*> template specialization)(since C++11)

以原子方式增加或减少当前值。操作是读-修改-写操作.

1%29执行原子前增量.。相当于fetch_add(1)+1...

2%29执行原子后增量.。相当于fetch_add(1)...

3%29执行原子预减量.。相当于fetch_sub(1)-1

4%29执行原子后减量.。相当于fetch_sub(1)...

签名Integral类型,算法定义为使用两种补码表示形式。没有未定义的结果。为T*类型,结果可能是一个未定义的地址,但否则操作就没有未定义的行为。

参数

%280%29

返回值

修改后原子变量的值为1,3%29。形式上,在紧接此函数的效果之前的修改顺序成*this...

修改前原子变量的值为2,4%,29。形式上,此函数的效果之前的值在修改顺序成*this...

例外

noexcept规格:

noexcept

注记

与大多数预增量和预减量操作符不同,原子类型的预增量和预减量运算符不返回对修改对象的引用。它们返回存储值的副本。

另见

fetch_addatomically adds the argument to the value stored in the atomic object and obtains the value held previously (public member function)
fetch_subatomically subtracts the argument from the value stored in the atomic object and obtains the value held previously (public member function)
operator+=operator-=operator&=operator|=operator^=adds, subtracts, or performs bitwise AND, OR, XOR with the atomic value (public member function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cpPreference.com/w/cpp/原子/原子/操作符[医]阿瑞斯