std::atomic::operator+=,-=,&=,|=,^=

仅为 atomic<Integral>(C++11)atomic<Floating>(C++20) 模板特化的成员
(1)
T operator+=( T arg ) noexcept;
T operator+=( T arg ) volatile noexcept;
仅为 atomic<T*> 模板特化的成员
(1)
T* operator+=( std::ptrdiff_t arg ) noexcept;
T* operator+=( std::ptrdiff_t arg ) volatile noexcept;
仅为 atomic<Integral>(C++11)atomic<Floating>(C++20) 模板特化的成员
(2)
T operator-=( T arg ) noexcept;
T operator-=( T arg ) volatile noexcept;
仅为 atomic<T*> 模板特化的成员
(2)
T* operator-=( std::ptrdiff_t arg ) noexcept;
T* operator-=( std::ptrdiff_t arg ) volatile noexcept;
仅为 atomic<Integral> 模板特化的成员
(3)
T operator&=( T arg ) noexcept;
T operator&=( T arg ) volatile noexcept;
(4)
T operator|=( T arg ) noexcept;
T operator|=( T arg ) volatile noexcept;
(5)
T operator^=( T arg ) noexcept;
T operator^=( T arg ) volatile noexcept;

原子地以涉及先前值和 arg 的计算结果替换当前值。操作是读-修改-写操作。

1) 进行原子加法。等价于 fetch_add(arg) + arg 。
2) 进行原子减法。等价于 fetch_sub(arg) - arg 。
3) 进行原子逐位与。等价于 fetch_and(arg) & arg 。
4) 进行原子逐位或。等价于 fetch_or(arg) | arg 。
5) 进行原子逐位异或。等价于 fetch_xor(arg) ^ arg 。

对于有符号整数 (Integral) 类型,算术定义为使用补码表示。无未定义结果。对于 T* 类型,结果可能为未定义地址,但其他情况下操作无未定义行为。

目录

参数

arg - 算术运算的参数

返回值

返回值(即应用对应二元运算符到 *this修改顺序中立即前趋于成员对应函数效果的值)

注意

不同于大多数复合赋值运算符,原子类型的复合赋值运算符不返回到其左侧运算数的引用。它们替而返回存储的值的副本。

参阅

令原子值增加或减少一
(公开成员函数)

版本历史

  • (当前 | 先前 2017年12月9日 (六) 18:26Fruderica讨论 | 贡献. . (2,849字节) (-171). . (fmt) (撤销)
  • 当前 | 先前 2017年12月8日 (五) 18:29Fruderica讨论 | 贡献. . (3,020字节) (+22). . (p0020r6) (撤销)
  • 当前 | 先前 2017年10月10日 (二) 03:36Fruderica讨论 | 贡献. . (2,998字节) (-420). . (撤销)
  • 当前 | 先前 2013年7月2日 (二) 07:16P12bot讨论 | 贡献 . . (3,418字节) (-140). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 16:39P12bot讨论 | 贡献 . . (3,558字节) (+329). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 09:22P12讨论 | 贡献 . . (3,229字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (3,229字节) (-113). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 13:13P12讨论 | 贡献 . . (3,342字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (3,342字节) (+3,342). . (Translated from the English version using Google Translate)