Skip to content

Latest commit

 

History

History
81 lines (58 loc) · 1.6 KB

op_assign.md

File metadata and controls

81 lines (58 loc) · 1.6 KB

operator=

  • atomic[meta header]
  • std[meta namespace]
  • atomic_ref[meta class]
  • function[meta id-type]
  • cpp20[meta cpp]
T
  operator=(T desired) const noexcept;          // (1) C++20
constexpr value_type
  operator=(value_type desired) const noexcept; // (1) C++26

概要

値を書き込む

テンプレートパラメータ制約

効果

以下と等価:

store(desired);
return desired;
  • store[link store.md]

例外

投げない

備考

  • 参照先の変更ではなく、参照先の値を書き換えるので注意

#include <iostream>
#include <atomic>

int main()
{
  int value = 3;
  std::atomic_ref<int> x{value};

  x = 2;

  std::cout << value << std::endl;
}
  • x = 2;[color ff0000]

出力

2

バージョン

言語

  • C++20

処理系

参照