- atomic[meta header]
- std[meta namespace]
- function template[meta id-type]
- cpp26[meta cpp]
namespace std {
template <classT>
T
atomic_fetch_max(volatile atomic<T>* object,
typename atomic<T>::value_type operand) noexcept; // (1) C++26
template <classT>
constexpr T
atomic_fetch_max(atomic<T>* object,
typename atomic<T>::value_type operand) noexcept; // (2) C++26
}
- atomic[link /reference/atomic/atomic.md]
アトミックに最大値を取得する
- (1), (2) : 型
T
がオブジェクト型であること。型T
がvoid*
や関数ポインタであってはならない - (1) :
atomic<T>::is_always_lock_free
がtrue
であること
memory_order_seq_cst
のメモリオーダーにしたがって、std::max()
アルゴリズムのように*object
が保持する値とoperand
の最大値を求めて返す
投げない
#include <iostream>
#include <atomic>
int main()
{
std::atomic<int> x(3);
int ret = std::atomic_fetch_max(&x, 2);
std::cout << ret << std::endl;
}
- std::atomic_fetch_max[color ff0000]
3
- C++26