Skip to content

Commit eef0639

Browse files
committed
C++26対応としてatomic(_ref)にfetch_max/minを追加 (close #1188)
1 parent 2ad32d5 commit eef0639

File tree

12 files changed

+587
-1
lines changed

12 files changed

+587
-1
lines changed

lang/cpp26.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ C++26とは、2026年中に改訂される予定の、C++バージョンの通
224224

225225
### 並行・並列・非同期処理
226226
- [`<execution>`](/reference/execution.md)に汎用的な非同期実行を管理するフレームワークを追加
227-
- [`std::atomic`](/reference/atomic/atomic.md)オブジェクトに対する2つの値の最大値・最小値を取得する関数として、メンバ関数[`fetch_max()`](/reference/atomic/atomic/fetch_max.md.nolink)[`fetch_min()`](/reference/atomic/atomic/fetch_min.md.nolink)、非メンバ関数として[`std::atomic_fetch_max`](/reference/atomic/atomic_fetch_max.md.nolink)[`std::atomic_fetch_max_explicit`](/reference/atomic/atomic_fetch_max_explicit.md.nolink)[`std::atomic_fetch_min`](/reference/atomic/atomic_fetch_min.md.nolink)[`std::atomic_fetch_min_explicit`](/reference/atomic/atomic_fetch_min_explicit.md.nolink)を追加
227+
- [`std::atomic`](/reference/atomic/atomic.md)オブジェクトに対する2つの値の最大値・最小値を取得する関数として、メンバ関数[`fetch_max()`](/reference/atomic/atomic/fetch_max.md)[`fetch_min()`](/reference/atomic/atomic/fetch_min.md)、非メンバ関数として[`std::atomic_fetch_max`](/reference/atomic/atomic_fetch_max.md)[`std::atomic_fetch_max_explicit`](/reference/atomic/atomic_fetch_max_explicit.md)[`std::atomic_fetch_min`](/reference/atomic/atomic_fetch_min.md)[`std::atomic_fetch_min_explicit`](/reference/atomic/atomic_fetch_min_explicit.md)を追加
228228
- [`std::atomic_ref`](/reference/atomic/atomic_ref.md)クラスに、参照するオブジェクトのアドレスを取得する[`address()`](/reference/atomic/atomic_ref/address.md.nolink)メンバ関数を追加
229229
- [`std::atomic`](/reference/atomic/atomic.md)クラスのテンプレートパラメータとしてCV修飾された型を禁止
230230
- [`std::atomic_ref`](/reference/atomic/atomic_ref.md)クラスのテンプレートパラメータとして、CV修飾された型を受け取れるようにした (内部でCV修飾が外される)

reference/atomic.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
| [`atomic_fetch_or_explicit`](atomic/atomic_fetch_or_explicit.md) | メモリオーダーを指定してOR演算(function template) | C++11 |
7676
| [`atomic_fetch_xor`](atomic/atomic_fetch_xor.md) | XOR演算(function template) | C++11 |
7777
| [`atomic_fetch_xor_explicit`](atomic/atomic_fetch_xor_explicit.md) | メモリオーダーを指定してXOR演算(function template) | C++11 |
78+
| [`atomic_fetch_max`](atomic/atomic_fetch_max.md) | 最大値取得(function template) | C++26 |
79+
| [`atomic_fetch_max_explicit`](atomic/atomic_fetch_max_explicit.md) | メモリオーダーを指定して最大値取得(function template) | C++26 |
80+
| [`atomic_fetch_min`](atomic/atomic_fetch_min.md) | 最小値取得(function template) | C++26 |
81+
| [`atomic_fetch_min_explicit`](atomic/atomic_fetch_min_explicit.md) | メモリオーダーを指定して最小値取得(function template) | C++26 |
7882

7983

8084
## アトミック型に対するブロッキング同期操作

reference/atomic/atomic.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ namespace std {
162162
| [`fetch_and`](atomic/fetch_and.md) | AND演算 | C++11 |
163163
| [`fetch_or`](atomic/fetch_or.md) | OR演算 | C++11 |
164164
| [`fetch_xor`](atomic/fetch_xor.md) | XOR演算 | C++11 |
165+
| [`fetch_max`](atomic/fetch_max.md) | 最大値取得 | C++26 |
166+
| [`fetch_min`](atomic/fetch_min.md) | 最小値取得 | C++26 |
165167
| [`operator++`](atomic/op_increment.md) | インクリメント | C++11 |
166168
| [`operator--`](atomic/op_decrement.md) | デクリメント | C++11 |
167169
| [`operator+=`](atomic/op_plus_assign.md) | 加算 | C++11 |
@@ -201,6 +203,8 @@ namespace std {
201203
|------|------|----------------|
202204
| [`fetch_add`](atomic/fetch_add.md) | 加算 | C++11 |
203205
| [`fetch_sub`](atomic/fetch_sub.md) | 減算 | C++11 |
206+
| [`fetch_max`](atomic/fetch_max.md) | 最大値取得 | C++26 |
207+
| [`fetch_min`](atomic/fetch_min.md) | 最小値取得 | C++26 |
204208
| [`operator++`](atomic/op_increment.md) | インクリメント | C++11 |
205209
| [`operator--`](atomic/op_decrement.md) | デクリメント | C++11 |
206210
| [`operator+=`](atomic/op_plus_assign.md) | 加算 | C++11 |
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# fetch_max
2+
* atomic[meta header]
3+
* std[meta namespace]
4+
* atomic[meta class]
5+
* function[meta id-type]
6+
* cpp26[meta cpp]
7+
8+
```cpp
9+
T fetch_max(difference_type operand,
10+
memory_order order = memory_order_seq_cst
11+
) const noexcept; // (1) C++26
12+
```
13+
* memory_order[link /reference/atomic/memory_order.md]
14+
* memory_order_seq_cst[link /reference/atomic/memory_order.md]
15+
16+
## 概要
17+
最大値を取得する。
18+
19+
この関数は、`*this`が保持する値と`operand`の大きい方を返す。
20+
21+
22+
## テンプレートパラメータ制約
23+
- (1) : `std::atomic<T*>`の場合、型`T`がオブジェクト型であること。型`T`が`void*`や関数ポインタであってはならない
24+
25+
26+
## 効果
27+
`order`で指定されたメモリオーダーにしたがって、[`std::max()`](/reference/algorithm/max.md)アルゴリズムのように`*this`が保持する値と`operand`の最大値を求めて返す
28+
29+
30+
## 例外
31+
投げない
32+
33+
34+
## 備考
35+
- この関数は、`atomic`クラスの整数型、ポインタに対する特殊化で定義される (浮動小数点数型に対しては定義されない)
36+
- ポインタ型
37+
- ポインタが異なる完全型オブジェクトを指している場合、`<`演算子による比較は狭義の弱順序を確立しない
38+
39+
40+
## 例
41+
```cpp example
42+
#include <iostream>
43+
#include <atomic>
44+
45+
int main()
46+
{
47+
std::atomic<int> x(3);
48+
49+
int ret = x.fetch_max(2);
50+
51+
std::cout << ret << std::endl;
52+
}
53+
```
54+
* fetch_max[color ff0000]
55+
56+
57+
### 出力
58+
```
59+
3
60+
```
61+
62+
## バージョン
63+
### 言語
64+
- C++26
65+
66+
### 処理系
67+
- [Clang](/implementation.md#clang): 19 [mark noimpl]
68+
- [GCC](/implementation.md#gcc): 14 [mark noimpl]
69+
70+
71+
## 参照
72+
- [P0493R5 Atomic minimum/maximum](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p0493r5.pdf)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# fetch_min
2+
* atomic[meta header]
3+
* std[meta namespace]
4+
* atomic[meta class]
5+
* function[meta id-type]
6+
* cpp26[meta cpp]
7+
8+
```cpp
9+
T fetch_min(difference_type operand,
10+
memory_order order = memory_order_seq_cst
11+
) const noexcept; // (1) C++26
12+
```
13+
* memory_order[link /reference/atomic/memory_order.md]
14+
* memory_order_seq_cst[link /reference/atomic/memory_order.md]
15+
16+
## 概要
17+
最小値を取得する。
18+
19+
この関数は、`*this`が保持する値と`operand`の大きい方を返す。
20+
21+
22+
## テンプレートパラメータ制約
23+
- (1) : `std::atomic<T*>`の場合、型`T`がオブジェクト型であること。型`T`が`void*`や関数ポインタであってはならない
24+
25+
26+
## 効果
27+
`order`で指定されたメモリオーダーにしたがって、[`std::min()`](/reference/algorithm/min.md)アルゴリズムのように`*this`が保持する値と`operand`の最小値を求めて返す
28+
29+
30+
## 例外
31+
投げない
32+
33+
34+
## 備考
35+
- この関数は、`atomic`クラスの整数型、ポインタに対する特殊化で定義される (浮動小数点数型に対しては定義されない)
36+
- ポインタ型
37+
- ポインタが異なる完全型オブジェクトを指している場合、`<`演算子による比較は狭義の弱順序を確立しない
38+
39+
40+
## 例
41+
```cpp example
42+
#include <iostream>
43+
#include <atomic>
44+
45+
int main()
46+
{
47+
std::atomic<int> x(3);
48+
49+
int ret = x.fetch_min(2);
50+
51+
std::cout << ret << std::endl;
52+
}
53+
```
54+
* fetch_min[color ff0000]
55+
56+
57+
### 出力
58+
```
59+
2
60+
```
61+
62+
## バージョン
63+
### 言語
64+
- C++26
65+
66+
### 処理系
67+
- [Clang](/implementation.md#clang): 19 [mark noimpl]
68+
- [GCC](/implementation.md#gcc): 14 [mark noimpl]
69+
70+
71+
## 参照
72+
- [P0493R5 Atomic minimum/maximum](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p0493r5.pdf)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# atomic_fetch_max
2+
* atomic[meta header]
3+
* std[meta namespace]
4+
* function template[meta id-type]
5+
* cpp26[meta cpp]
6+
7+
```cpp
8+
namespace std {
9+
template <classT>
10+
T atomic_fetch_max(volatile atomic<T>* object,
11+
typename atomic<T>::value_type operand) noexcept; // (1) C++26
12+
13+
template <classT>
14+
T atomic_fetch_max(atomic<T>* object,
15+
typename atomic<T>::value_type operand) noexcept; // (2) C++26
16+
}
17+
```
18+
* atomic[link /reference/atomic/atomic.md]
19+
20+
21+
## 概要
22+
アトミックに最大値を取得する
23+
24+
25+
## テンプレートパラメータ制約
26+
- (1), (2) : 型`T`がオブジェクト型であること。型`T`が`void*`や関数ポインタであってはならない
27+
- (1) : `atomic<T>::is_always_lock_free`が`true`であること
28+
29+
30+
## 効果
31+
[`memory_order_seq_cst`](memory_order.md)のメモリオーダーにしたがって、[`std::max()`](/reference/algorithm/max.md)アルゴリズムのように`*object`が保持する値と`operand`の最大値を求めて返す
32+
33+
34+
## 例外
35+
投げない
36+
37+
38+
## 例
39+
```cpp example
40+
#include <iostream>
41+
#include <atomic>
42+
43+
int main()
44+
{
45+
std::atomic<int> x(3);
46+
47+
int ret = std::atomic_fetch_max(&x, 2);
48+
49+
std::cout << ret << std::endl;
50+
}
51+
```
52+
* std::atomic_fetch_max[color ff0000]
53+
54+
### 出力
55+
```
56+
3
57+
```
58+
59+
60+
## バージョン
61+
### 言語
62+
- C++26
63+
64+
65+
### 処理系
66+
- [Clang](/implementation.md#clang): 19 [mark noimpl]
67+
- [GCC](/implementation.md#gcc): 14 [mark noimpl]
68+
69+
70+
## 参照
71+
- [P0493R5 Atomic minimum/maximum](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p0493r5.pdf)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# atomic_fetch_max_explicit
2+
* atomic[meta header]
3+
* std[meta namespace]
4+
* function template[meta id-type]
5+
* cpp26[meta cpp]
6+
7+
```cpp
8+
namespace std {
9+
template <class T>
10+
T atomic_fetch_max_explicit(
11+
volatile atomic<T>* object,
12+
typename atomic<T>::value_type operand,
13+
memory_order order) noexcept; // (1) C++26
14+
15+
template <class T>
16+
T atomic_fetch_max_explicit(
17+
atomic<T>* object,
18+
typename atomic<T>::value_type operand,
19+
memory_order order) noexcept; // (2) C++26
20+
}
21+
```
22+
* atomic[link atomic.md]
23+
* memory_order[link memory_order.md]
24+
25+
## 概要
26+
アトミックに最大値を取得する
27+
28+
29+
## テンプレートパラメータ制約
30+
- (1), (2) : 型`T`がオブジェクト型であること。型`T`が`void*`や関数ポインタであってはならない
31+
- (1) : `atomic<T>::is_always_lock_free`が`true`であること
32+
33+
34+
## 効果
35+
`order`で指定されたメモリオーダーにしたがって、[`std::max()`](/reference/algorithm/max.md)アルゴリズムのように`*object`が保持する値と`operand`の最大値を求めて返す
36+
37+
38+
## 例外
39+
投げない
40+
41+
42+
## 例
43+
```cpp example
44+
#include <iostream>
45+
#include <atomic>
46+
47+
int main()
48+
{
49+
std::atomic<int> x(3);
50+
51+
int ret = std::atomic_fetch_max_explicit(&x, 2, std::memory_order_seq_cst);
52+
std::cout << ret << std::endl;
53+
}
54+
```
55+
* std::atomic_fetch_add_maxlicit[color ff0000]
56+
57+
58+
### 出力
59+
```
60+
3
61+
```
62+
63+
## バージョン
64+
### 言語
65+
- C++26
66+
67+
### 処理系
68+
- [Clang](/implementation.md#clang): 19 [mark noimpl]
69+
- [GCC](/implementation.md#gcc): 14 [mark noimpl]
70+
71+
72+
## 参照
73+
- [P0493R5 Atomic minimum/maximum](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p0493r5.pdf)

0 commit comments

Comments
 (0)