Skip to content

Latest commit

 

History

History
74 lines (52 loc) · 1.65 KB

atomic_fetch_max.md

File metadata and controls

74 lines (52 loc) · 1.65 KB

atomic_fetch_max

  • 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がオブジェクト型であること。型Tvoid*や関数ポインタであってはならない
  • (1) : atomic<T>::is_always_lock_freetrueであること

効果

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

処理系

  • Clang: 19 [mark noimpl]
  • GCC: 14 [mark noimpl]

参照