Skip to content

Commit c551d63

Browse files
committed
repeat_view : メンバ関数を追加 #713
1 parent d3f5ac2 commit c551d63

File tree

7 files changed

+348
-13
lines changed

7 files changed

+348
-13
lines changed

GLOBAL_QUALIFY_LIST.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
* std::end[link /reference/iterator/end.md]
169169
* std::next[link /reference/iterator/next.md]
170170
* std::ostream_iterator[link /reference/iterator/ostream_iterator.md]
171+
* unreachable_sentinel_t[link /reference/iterator/unreachable_sentinel_t.md]
171172
* <latch>[link /reference/latch.md]
172173
* <limits>[link /reference/limits.md]
173174
* std::numeric_limits[link /reference/limits/numeric_limits.md]
@@ -182,6 +183,7 @@
182183
* std::dextents[link /reference/mdspan/extents.md]
183184
* std::mdspan[link /reference/mdspan/mdspan.md]
184185
* <memory>[link /reference/memory.md]
186+
* addressof[link /reference/memory/addressof.md]
185187
* std::allocator[link /reference/memory/allocator.md]
186188
* std::shared_ptr[link /reference/memory/shared_ptr.md]
187189
* std::unique_ptr[link /reference/memory/unique_ptr.md]
@@ -292,6 +294,7 @@
292294
* std::forward_as_tuple[link /reference/tuple/forward_as_tuple.md]
293295
* std::tuple[link /reference/tuple/tuple.md]
294296
* std::tie[link /reference/tuple/tie.md]
297+
* tuple[link /reference/tuple/tuple.md]
295298
* <type_traits>[link /reference/type_traits.md]
296299
* common_type_t[link /reference/type_traits/common_type.md]
297300
* std::common_type_t[link /reference/type_traits/common_type.md]
@@ -322,6 +325,8 @@
322325
* std::make_pair[link /reference/utility/make_pair.md]
323326
* std::pair[link /reference/utility/pair.md]
324327
* pair[link /reference/utility/pair.md]
328+
* piecewise_construct_t[link /reference/utility/piecewise_construct_t.md]
329+
* piecewise_construct[link /reference/utility/piecewise_construct_t.md]
325330
* <valarray>[link /reference/valarray.md]
326331
* std::valarray[link /reference/valarray/valarray.md]
327332
* <variant>[link /reference/variant.md]

reference/ranges/repeat_view.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ namespace std::ranges {
4747
4848
| 名前 | 説明 | 対応バージョン |
4949
|--------------------------------------------------|----------------------------------|----------------|
50-
| [`(constructor)`](repeat_view/op_constructor.md.nolink) | コンストラクタ | C++23 |
51-
| [`begin`](repeat_view/begin.md.nolink) | 先頭を指すイテレータを取得する | C++23 |
52-
| [`end`](repeat_view/end.md.nolink) | 番兵を取得する | C++23 |
53-
| [`size`](repeat_view/data.md.nolink) | 配列の先頭へのポインタを取得する | C++23 |
50+
| [`(constructor)`](repeat_view/op_constructor.md) | コンストラクタ | C++23 |
51+
| [`begin`](repeat_view/begin.md) | 先頭を指すイテレータを取得する | C++23 |
52+
| [`end`](repeat_view/end.md) | 番兵を取得する | C++23 |
53+
| [`size`](repeat_view/size.md) | 配列の先頭へのポインタを取得する | C++23 |
5454
5555
## 継承しているメンバ関数
5656
@@ -60,19 +60,22 @@ namespace std::ranges {
6060
| [`front`](view_interface/front.md) | 先頭要素への参照を取得する | C++23 |
6161
| [`back`](view_interface/back.md) | 末尾要素への参照を取得する | C++23 |
6262
| [`operator[]`](view_interface/op_at.md) | 要素へアクセスする | C++23 |
63+
| [`empty`](view_interface/empty.md) | Rangeが空かどうかを判定する | C++23 |
64+
| [`cbegin`](view_interface/cbegin.md) | 定数イテレータを取得する | C++23 |
65+
| [`cend`](view_interface/cend.md) | 定数イテレータ(番兵)を取得する | C++23 |
6366
6467
## メンバ型
6568
66-
| 名前 | 説明 | 対応バージョン |
67-
|-------------------------------------------|------------------------------|----------------|
68-
| [`iterator`](repeat_view/iterator.md) | イテレータ型(説明専用) | C++23 |
69+
| 名前 | 説明 | 対応バージョン |
70+
|---------------------------------------|------------------------------|----------------|
71+
| [`iterator`](repeat_view/iterator.md) | イテレータ型(説明専用) | C++23 |
6972
7073
7174
## 推論補助
7275
73-
| 名前 | 説明 | 対応バージョン |
74-
|-------------------------------------------------------|------------------------------|----------------|
75-
| [`(deduction_guide)`](repeat_view/op_deduction_guide.md.nolink) | クラステンプレートの推論補助 | C++23 |
76+
| 名前 | 説明 | 対応バージョン |
77+
|----------------------------------------------------------|------------------------------|----------------|
78+
| [`(deduction_guide)`](repeat_view/op_deduction_guide.md) | クラステンプレートの推論補助 | C++23 |
7679
7780
## 例
7881
```cpp example
@@ -99,10 +102,10 @@ int main() {
99102
- C++23
100103

101104
### 処理系
102-
- [Clang](/implementation.md#clang): ?
103-
- [GCC](/implementation.md#gcc): ?
105+
- [Clang](/implementation.md#clang): 17 [mark verified]
106+
- [GCC](/implementation.md#gcc): 13 [mark verified]
104107
- [ICC](/implementation.md#icc): ?
105-
- [Visual C++](/implementation.md#visual_cpp): ?
108+
- [Visual C++](/implementation.md#visual_cpp): 2022 Update 6 [mark verified]
106109

107110
## 参照
108111
- [N4950 26 Ranges library](https://timsong-cpp.github.io/cppwp/n4950/ranges)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# begin
2+
* ranges[meta header]
3+
* std::ranges[meta namespace]
4+
* repeat_view[meta class]
5+
* function[meta id-type]
6+
* cpp23[meta cpp]
7+
8+
```cpp
9+
constexpr iterator begin() const; // (1) C++23
10+
```
11+
* iterator[link iterator.md]
12+
13+
## 概要
14+
15+
`view`の先頭要素を指すイテレータを取得する。
16+
17+
18+
## 戻り値
19+
以下と等価:
20+
21+
```cpp
22+
return iterator(addressof(*value_));
23+
```
24+
25+
26+
##
27+
28+
```cpp example
29+
#include <ranges>
30+
#include <iostream>
31+
32+
int main() {
33+
auto r = std::views::repeat(42, 3);
34+
auto it = r.begin();
35+
std::cout << *it << std::endl; // 42
36+
}
37+
```
38+
* begin[color ff0000]
39+
40+
### 出力
41+
42+
```
43+
42
44+
```
45+
46+
## バージョン
47+
### 言語
48+
- C++23
49+
50+
### 処理系
51+
- [Clang](/implementation.md#clang): 17 [mark verified]
52+
- [GCC](/implementation.md#gcc): 13 [mark verified]
53+
- [ICC](/implementation.md#icc): ?
54+
- [Visual C++](/implementation.md#visual_cpp): 2022 Update 6 [mark verified]
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# end
2+
* ranges[meta header]
3+
* std::ranges[meta namespace]
4+
* repeat_view[meta class]
5+
* function[meta id-type]
6+
* cpp23[meta cpp]
7+
8+
```cpp
9+
constexpr iterator end() const
10+
requires (!same_as<Bound, unreachable_sentinel_t>); // (1) C++23
11+
```
12+
13+
## 概要
14+
15+
番兵を取得する。
16+
17+
18+
## 戻り値
19+
以下と等価:
20+
21+
```cpp
22+
return iterator(addressof(*value_), bound_);
23+
```
24+
25+
##
26+
27+
```cpp example
28+
#include <ranges>
29+
#include <iostream>
30+
31+
int main() {
32+
auto r = std::views::repeat(42, 3);
33+
auto it = r.begin();
34+
auto last = r.end();
35+
36+
for (; it != last; ++it) {
37+
std::cout << *it << ' ';
38+
}
39+
}
40+
```
41+
* end[color ff0000]
42+
* begin()[link begin.md]
43+
44+
### 出力
45+
46+
```
47+
42 42 42
48+
```
49+
50+
## バージョン
51+
### 言語
52+
- C++23
53+
54+
### 処理系
55+
- [Clang](/implementation.md#clang): 17 [mark verified]
56+
- [GCC](/implementation.md#gcc): 13 [mark verified]
57+
- [ICC](/implementation.md#icc): ?
58+
- [Visual C++](/implementation.md#visual_cpp): 2022 Update 6 [mark verified]
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# コンストラクタ
2+
* ranges[meta header]
3+
* std::ranges[meta namespace]
4+
* repeat_view[meta class]
5+
* function[meta id-type]
6+
* cpp23[meta cpp]
7+
8+
```cpp
9+
repeat_view()
10+
requires default_initializable<T> = default; // (1) C++23
11+
12+
constexpr explicit
13+
repeat_view(const T& value, Bound bound = Bound())
14+
requires copy_constructible<T>; // (2) C++23
15+
16+
constexpr explicit
17+
repeat_view(T&& value, Bound bound = Bound()); // (3) C++23
18+
19+
template <class... TArgs, class... BoundArgs>
20+
requires constructible_from<T, TArgs...> &&
21+
constructible_from<Bound, BoundArgs...>
22+
constexpr explicit
23+
repeat_view(piecewise_construct_t,
24+
tuple<TArgs...> value_args,
25+
tuple<BoundArgs...> bound_args = tuple<>{}); // (4) C++23
26+
```
27+
28+
## 概要
29+
[`repeat_view`](../repeat_view.md)オブジェクトを構築する。
30+
31+
- (1) : デフォルト構築
32+
- (2) : `value`と`bound`をコピーして、`*this`に保持する
33+
- (3) : `value`をムーブし、`bound`をコピーして、`*this`に保持する
34+
- (4) : 値型`T`のコンストラクタ引数をタプルにまとめた`value_args`と、繰り返し回数を表す型`Bound`のコンストラクタ引数をタプルにまとめた`bound_args`を転送して、オブジェクトを内部で構築して`*this`に保持する
35+
36+
37+
## 事前条件
38+
- (1), (2) :
39+
- 型`Bound`が型[`unreachable_sentinel_t`](/reference/iterator/unreachable_sentinel_t.md)でないこと
40+
- `bound >= 0`であること
41+
42+
43+
## 効果
44+
45+
- (2) : `value_`を`value`で初期化する
46+
- (3) : `value_`を[`std::move`](/reference/utility/move.md)`(value)`で初期化する
47+
- (4) :
48+
- `value_`を[`make_from_tuple`](/reference/tuple/make_from_tuple.md)`<T>(`[`std::move`](/reference/utility/move.md)`(value_args))`で初期化する
49+
- `bound_`を[`make_from_tuple`](/reference/tuple/make_from_tuple.md)`<Bound>(`[`std::move`](/reference/utility/move.md)`(bound_args))`で初期化する
50+
- `bound`が型`unreachable_sentinel_t`である場合、もしくは`bound < 0`である場合、未定義動作を引き起こす
51+
52+
53+
## 例
54+
```cpp example
55+
#include <iostream>
56+
#include <ranges>
57+
#include <string>
58+
59+
int main() {
60+
// (2) コピー構築
61+
{
62+
std::string s1 = "hello";
63+
for (const std::string& x : std::views::repeat(s1, 3)) {
64+
std::cout << x << std::endl;
65+
}
66+
}
67+
std::cout << std::endl;
68+
69+
// (3) ムーブ構築
70+
{
71+
std::string s1 = "hello";
72+
for (const std::string& x : std::views::repeat(std::move(s1), 3)) {
73+
std::cout << x << std::endl;
74+
}
75+
}
76+
std::cout << std::endl;
77+
78+
// (4) コンストラクタ引数から構築
79+
{
80+
auto r = std::ranges::repeat_view<std::string, int>{
81+
std::piecewise_construct,
82+
std::make_tuple(3, 'a'),
83+
std::make_tuple(3)
84+
};
85+
for (const std::string& x : r) {
86+
std::cout << x << std::endl;
87+
}
88+
}
89+
}
90+
```
91+
* std::ranges::repeat_view[color ff0000]
92+
* std::views::repeat[color ff0000]
93+
94+
### 出力
95+
```
96+
hello
97+
hello
98+
hello
99+
100+
hello
101+
hello
102+
hello
103+
104+
aaa
105+
aaa
106+
aaa
107+
```
108+
109+
## バージョン
110+
### 言語
111+
- C++23
112+
113+
### 処理系
114+
- [Clang](/implementation.md#clang): 17 [mark verified]
115+
- [GCC](/implementation.md#gcc): 13 [mark verified]
116+
- [ICC](/implementation.md#icc): ?
117+
- [Visual C++](/implementation.md#visual_cpp): 2022 Update 6 [mark verified]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# 推論補助
2+
* ranges[meta header]
3+
* std::ranges[meta namespace]
4+
* function[meta id-type]
5+
* cpp20[meta cpp]
6+
7+
```cpp
8+
namespace std::ranges {
9+
template<class T, class Bound = unreachable_sentinel_t>
10+
repeat_view(T, Bound = Bound()) -> repeat_view<T, Bound>;
11+
}
12+
```
13+
14+
## 概要
15+
16+
[`repeat_view`](../repeat_view.md)クラステンプレートの型推論補助。
17+
18+
19+
## 例
20+
```cpp example
21+
#include <iostream>
22+
#include <ranges>
23+
24+
int main() {
25+
auto r = std::ranges::repeat_view(42, 3);
26+
for (int x : r) {
27+
std::cout << x << std::endl;
28+
}
29+
}
30+
31+
```
32+
33+
### 出力
34+
```
35+
42
36+
42
37+
42
38+
```
39+
40+
## バージョン
41+
### 言語
42+
- C++23
43+
44+
### 処理系
45+
- [Clang](/implementation.md#clang): 17 [mark verified]
46+
- [GCC](/implementation.md#gcc): 13 [mark verified]
47+
- [ICC](/implementation.md#icc): ?
48+
- [Visual C++](/implementation.md#visual_cpp): 2022 Update 6 [mark verified]

0 commit comments

Comments
 (0)