Skip to content

Commit 319fdf9

Browse files
committed
algorithm/fill : C++26波カッコ初期化に対応 #1311
1 parent a2bacbe commit 319fdf9

File tree

2 files changed

+140
-19
lines changed

2 files changed

+140
-19
lines changed

reference/algorithm/fill.md

Lines changed: 82 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,49 @@
55

66
```cpp
77
namespace std {
8-
template <class ForwardIterator, class T>
9-
void fill(ForwardIterator first,
10-
ForwardIterator last,
11-
const T& value); // (1) C++03
12-
13-
template <class ForwardIterator, class T>
14-
constexpr void fill(ForwardIterator first,
15-
ForwardIterator last,
16-
const T& value); // (1) C++20
17-
18-
template <class ExecutionPolicy, class ForwardIterator,
8+
template <class ForwardIterator,
9+
class T>
10+
void
11+
fill(ForwardIterator first,
12+
ForwardIterator last,
13+
const T& value); // (1) C++03
14+
template <class ForwardIterator,
1915
class T>
20-
void fill(ExecutionPolicy&& exec,
21-
ForwardIterator first,
22-
ForwardIterator last,
23-
const T& value); // (2) C++17
16+
constexpr void
17+
fill(ForwardIterator first,
18+
ForwardIterator last,
19+
const T& value); // (1) C++20
20+
template <class ForwardIterator,
21+
class T = typename iterator_traits<ForwardIterator>::value_type>
22+
constexpr void
23+
fill(ForwardIterator first,
24+
ForwardIterator last,
25+
const T& value); // (1) C++20
26+
27+
template <class ExecutionPolicy,
28+
class ForwardIterator,
29+
class T>
30+
void
31+
fill(ExecutionPolicy&& exec,
32+
ForwardIterator first,
33+
ForwardIterator last,
34+
const T& value); // (2) C++17
35+
template <class ExecutionPolicy,
36+
class ForwardIterator,
37+
class T = typename iterator_traits<ForwardIterator>::value_type>
38+
void
39+
fill(ExecutionPolicy&& exec,
40+
ForwardIterator first,
41+
ForwardIterator last,
42+
const T& value); // (2) C++26
2443
}
2544
```
2645
2746
## 概要
2847
イテレータ範囲`[first, last)`のすべての要素に指定された値を書き込む。
2948
3049
31-
## 要件
50+
## 適格要件
3251
`value` は `output iterator` へ書き込み可能でなければならない
3352
3453
@@ -40,7 +59,17 @@ namespace std {
4059
正確に `last - first` 回の代入を行う
4160
4261
62+
## 備考
63+
- (1), (2) :
64+
- C++26 : 引数として波カッコ初期化`{}`を受け付ける
65+
```cpp
66+
std::vector<T> v;
67+
std::fill(v.begin(), v.end(), {a, b});
68+
```
69+
70+
4371
## 例
72+
### 基本的な使い方
4473
```cpp example
4574
#include <algorithm>
4675
#include <iostream>
@@ -57,11 +86,45 @@ int main() {
5786
```
5887
* std::fill[color ff0000]
5988

60-
### 出力
89+
#### 出力
6190
```
6291
3,3,3,3,3,
6392
```
6493

94+
### 波カッコ初期化を入力として使用する (C++26)
95+
```cpp example
96+
#include <algorithm>
97+
#include <iostream>
98+
#include <vector>
99+
100+
struct Point {
101+
int x;
102+
int y;
103+
104+
bool operator==(const Point& other) const = default;
105+
};
106+
107+
int main() {
108+
std::vector<Point> v(5);
109+
110+
std::fill(v.begin(), v.end(), {1, 2});
111+
112+
for (const Point& p : v) {
113+
std::cout << p.x << "," << p.y << std::endl;
114+
}
115+
}
116+
```
117+
* std::fill[color ff0000]
118+
119+
#### 出力
120+
```
121+
1,2
122+
1,2
123+
1,2
124+
1,2
125+
1,2
126+
```
127+
65128
66129
## 実装例
67130
```cpp
@@ -75,3 +138,5 @@ void fill(ForwardIterator first, ForwardIterator last, const T& value) {
75138

76139
## 参照
77140
- [P0202R3 Add Constexpr Modifiers to Functions in `<algorithm>` and `<utility>` Headers](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0202r3.html)
141+
- [P2248R8 Enabling list-initialization for algorithms](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2248r8.html)
142+
- C++26で波カッコ初期化 (リスト初期化) に対応した

reference/algorithm/ranges_fill.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@ namespace std::ranges {
1111
sentinel_for<O> S>
1212
constexpr O
1313
fill(O first, S last, const T& value); // (1) C++20
14+
template <class I,
15+
sentinel_for<O> S,
16+
class T = iter_value_t<O>>
17+
requires output_iterator<O, const T&>
18+
constexpr O
19+
fill(O first, S last, const T& value); // (1) C++26
1420

1521
template <class T,
1622
output_range<const T&> R>
1723
constexpr borrowed_iterator_t<R>
1824
fill(R&& r, const T& value); // (2) C++20
19-
25+
template <class R,
26+
class T = range_value_t<R>>
27+
requires output_range<R, const T&>
28+
constexpr borrowed_iterator_t<R>
29+
fill(R&& r, const T& value); // (2) C++26
2030
}
2131
```
2232
* output_iterator[link /reference/iterator/output_iterator.md]
@@ -43,7 +53,17 @@ namespace std::ranges {
4353
正確に `last - first` 回の代入を行う
4454
4555
56+
## 備考
57+
- (1), (2) :
58+
- C++26 : 引数として波カッコ初期化`{}`を受け付ける
59+
```cpp
60+
std::vector<T> v;
61+
std::ranges::fill(v, {a, b});
62+
```
63+
64+
4665
## 例
66+
### 基本的な使い方
4767
```cpp example
4868
#include <algorithm>
4969
#include <iostream>
@@ -62,11 +82,45 @@ int main() {
6282
```
6383
* std::ranges::fill[color ff0000]
6484

65-
### 出力
85+
#### 出力
6686
```
6787
3,3,3,3,3,
6888
```
6989

90+
### 波カッコ初期化を入力として使用する (C++26)
91+
```cpp example
92+
#include <algorithm>
93+
#include <iostream>
94+
#include <vector>
95+
96+
struct Point {
97+
int x;
98+
int y;
99+
100+
bool operator==(const Point& other) const = default;
101+
};
102+
103+
int main() {
104+
std::vector<Point> v(5);
105+
106+
std::ranges::fill(v.begin(), v.end(), {1, 2});
107+
108+
for (const Point& p : v) {
109+
std::cout << p.x << "," << p.y << std::endl;
110+
}
111+
}
112+
```
113+
* std::ranges::fill[color ff0000]
114+
115+
#### 出力
116+
```
117+
1,2
118+
1,2
119+
1,2
120+
1,2
121+
1,2
122+
```
123+
70124
## バージョン
71125
### 言語
72126
- C++20
@@ -79,3 +133,5 @@ int main() {
79133
80134
## 参照
81135
- [N4861 25 Algorithms library](https://timsong-cpp.github.io/cppwp/n4861/algorithms)
136+
- [P2248R8 Enabling list-initialization for algorithms](https://open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2248r8.html)
137+
- C++26で波カッコ初期化 (リスト初期化) に対応した

0 commit comments

Comments
 (0)