- atomic[meta header]
- std[meta namespace]
- atomic[meta class]
- function[meta id-type]
- cpp11[meta cpp]
T operator|=(T operand) volatile noexcept; // (1) C++11
T operator|=(T operand) noexcept; // (2) C++11
OR演算を行う
- (1) :
- C++20 :
atomic<T>::is_always_lock_free
がtrue
であること
- C++20 :
以下と等価の式により、演算結果の値が返る:
return fetch_or(operand) | operand;
- fetch_or[link fetch_or.md]
投げない
この関数は、atomic
クラスの整数型に対する特殊化で定義される。
#include <iostream>
#include <atomic>
#include <bitset>
int main()
{
int a = 0x0b;
int b = 0x0e;
std::atomic<int> x(a);
x |= b;
std::cout << std::bitset<4>(a).to_string() << std::endl;
std::cout << std::bitset<4>(b).to_string() << std::endl;
std::cout << std::bitset<4>(x.load()).to_string() << std::endl;
}
- x |= b;[color ff0000]
- x.load()[link load.md]
- to_string()[link /reference/bitset/bitset/to_string.md]
1011
1110
1111
#include <iostream>
#include <atomic>
#include <thread>
#include <bitset>
int main()
{
std::atomic<int> x{0b0110};
// 複数スレッドでビット複合演算を呼んでも、
// 最終的に全てのスレッドでのビット複合演算が処理された値になる
std::thread t1 {[&x] {
x |= 0b0001;
}};
std::thread t2 {[&x] {
x |= 0b1000;
}};
t1.join();
t2.join();
int value = x.load();
std::cout << std::bitset<4>(value).to_string() << std::endl;
}
- x |= 0b0001;[color ff0000]
- x |= 0b1000;[color ff0000]
- x.load()[link load.md]
- to_string()[link /reference/bitset/bitset/to_string.md]
1111
- C++11
- Clang: 3.2
- GCC: 4.7.0
- Visual C++: 2012, 2013
- P1831R1 Deprecating
volatile
: library- C++20での、
volatile
版への制約追加
- C++20での、