Skip to content

Commit ff88ad3

Browse files
committed
drop_while_view : メンバ関数を追加 #713
1 parent 23b7fdf commit ff88ad3

File tree

8 files changed

+386
-6
lines changed

8 files changed

+386
-6
lines changed

GLOBAL_QUALIFY_LIST.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* synth-three-way[link /reference/exposition-only/synth-three-way-result.md]
99
* <algorithm>[link /reference/algorithm.md]
1010
* ExecutionPolicy[link /reference/execution/execution/execution_policy.md]
11+
* ranges::find_if_not[link /reference/algorithm/ranges/find_if_not.md]
1112
* std::copy[link /reference/algorithm/copy.md]
1213
* std::copy_n[link /reference/algorithm/copy_n.md]
1314
* std::for_each[link /reference/algorithm/for_each.md]

reference/ranges/drop_while_view.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ namespace std::ranges {
4949
5050
| 名前 | 説明 | 対応バージョン |
5151
|--------------------------------------------------------------|----------------------------------|----------------|
52-
| [`(constructor)`](drop_while_view/op_constructor.md.nolink) | コンストラクタ | C++20 |
53-
| [`base`](drop_while_view/base.md.nolink) | `V`の参照を取得する | C++20 |
54-
| [`pred`](drop_while_view/pred.md.nolink) | 述語を取得する | C++20 |
55-
| [`begin`](drop_while_view/begin.md.nolink) | 先頭を指すイテレータを取得する | C++20 |
56-
| [`end`](drop_while_view/end.md.nolink) | 番兵を取得する | C++20 |
52+
| [`(constructor)`](drop_while_view/op_constructor.md) | コンストラクタ | C++20 |
53+
| [`base`](drop_while_view/base.md) | `V`の参照を取得する | C++20 |
54+
| [`pred`](drop_while_view/pred.md) | 述語を取得する | C++20 |
55+
| [`begin`](drop_while_view/begin.md) | 先頭を指すイテレータを取得する | C++20 |
56+
| [`end`](drop_while_view/end.md) | 番兵を取得する | C++20 |
5757
5858
## 継承しているメンバ関数
5959
@@ -72,7 +72,7 @@ namespace std::ranges {
7272
7373
| 名前 | 説明 | 対応バージョン |
7474
|-------------------------------------------------------|------------------------------|----------------|
75-
| [`(deduction_guide)`](drop_while_view/op_deduction_guide.md.nolink) | クラステンプレートの推論補助 | C++20 |
75+
| [`(deduction_guide)`](drop_while_view/op_deduction_guide.md) | クラステンプレートの推論補助 | C++20 |
7676
7777
## 例
7878
```cpp example
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# base
2+
* ranges[meta header]
3+
* std::ranges[meta namespace]
4+
* drop_while_view[meta class]
5+
* function[meta id-type]
6+
* cpp20[meta cpp]
7+
8+
```cpp
9+
constexpr V base() const &
10+
requires copy_constructible<V>; // (1) C++20
11+
12+
constexpr V base() &&; // (2) C++20
13+
```
14+
15+
## 概要
16+
17+
メンバ変数として保持している、元の`view`を取得する。
18+
19+
## 効果
20+
21+
入力`view``V`)のオブジェクトを`base_`というメンバに保持するとして
22+
23+
- (1) : `return base_;` と等価
24+
- (2) : `return std::move(base_);` と等価
25+
26+
##
27+
28+
```cpp example
29+
#include <ranges>
30+
#include <vector>
31+
#include <iostream>
32+
33+
int main() {
34+
using std::ranges::view;
35+
36+
std::vector<int> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
37+
38+
std::ranges::drop_while_view r{vec, [](int x) { return x < 6; }};
39+
40+
// (1) コピーして取得
41+
view auto b1 = r.base();
42+
43+
// (2) ムーブして取得
44+
view auto b2 = std::move(r).base();
45+
46+
// 得られるのは元のRangeではなく、あくまでview
47+
static_assert(not std::same_as<decltype(b1), std::vector<int>>);
48+
static_assert( std::same_as<decltype(b1), std::ranges::ref_view<std::vector<int>>>);
49+
static_assert( std::same_as<decltype(b2), std::ranges::ref_view<std::vector<int>>>);
50+
}
51+
```
52+
* base[color ff0000]
53+
54+
### 出力
55+
56+
```
57+
```
58+
59+
## バージョン
60+
### 言語
61+
- C++20
62+
63+
### 処理系
64+
- [Clang](/implementation.md#clang): 13.0.0 [mark verified]
65+
- [GCC](/implementation.md#gcc): 10.1.0 [mark verified]
66+
- [ICC](/implementation.md#icc): ?
67+
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 10 [mark verified]
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# begin
2+
* ranges[meta header]
3+
* std::ranges[meta namespace]
4+
* drop_while_view[meta class]
5+
* function[meta id-type]
6+
* cpp20[meta cpp]
7+
8+
```cpp
9+
constexpr auto begin()
10+
requires (!simple-view<V>); // (1) C++20
11+
12+
constexpr auto begin() const
13+
requires range<const V> &&
14+
indirect_unary_predicate<
15+
const Pred,
16+
iterator_t<const V>
17+
>; // (2) C++20
18+
```
19+
20+
## 概要
21+
22+
`view`の先頭要素を指すイテレータを取得する。
23+
24+
## 戻り値
25+
先頭から条件を満たさない最初の要素を指すイテレータを返す。
26+
27+
- (1), (2) : 実装時にキャッシュした結果を返すか、以下と等価:
28+
```cpp
29+
return ranges::find_if_not(ranges::begin(base_), ranges::end(base_), pred_);
30+
```
31+
32+
ただし、`base_`は元の`view`を表すメンバ変数、`pred_`は述語を表すメンバ変数。
33+
34+
## 例
35+
36+
```cpp example
37+
#include <ranges>
38+
#include <vector>
39+
#include <iostream>
40+
41+
int main() {
42+
std::vector<int> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
43+
44+
std::ranges::drop_while_view r{vec, [](int x) { return x < 6; }};
45+
46+
auto it = r.begin();
47+
48+
int x = *it;
49+
std::cout << x << '\n';
50+
}
51+
```
52+
* begin[color ff0000]
53+
54+
### 出力
55+
56+
```
57+
6
58+
```
59+
60+
## バージョン
61+
### 言語
62+
- C++20
63+
64+
### 処理系
65+
- [Clang](/implementation.md#clang): 13.0.0 [mark verified]
66+
- [GCC](/implementation.md#gcc): 10.1.0 [mark verified]
67+
- [ICC](/implementation.md#icc): ?
68+
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 10 [mark verified]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# end
2+
* ranges[meta header]
3+
* std::ranges[meta namespace]
4+
* drop_while_view[meta class]
5+
* function[meta id-type]
6+
* cpp20[meta cpp]
7+
8+
```cpp
9+
constexpr auto end()
10+
requires (!simple-view<V>); // (1) C++20
11+
12+
constexpr auto end() const
13+
requires range<const V> &&
14+
indirect_unary_predicate<
15+
const Pred,
16+
iterator_t<const V>
17+
>; // (2) C++20
18+
```
19+
20+
## 概要
21+
番兵を取得する。
22+
23+
## 戻り値
24+
- (1), (2) : 以下と等価:
25+
```cpp
26+
return ranges::end(base_);
27+
```
28+
29+
ただし、`base_`は元の`view`を表すメンバ変数。
30+
31+
## 例
32+
33+
```cpp example
34+
#include <ranges>
35+
#include <vector>
36+
#include <iostream>
37+
38+
int main() {
39+
std::vector<int> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
40+
41+
std::ranges::drop_while_view r{vec, [](int x) { return x < 6; }};
42+
43+
auto it = r.begin();
44+
auto end_it = r.end();
45+
while (it != end_it) {
46+
int x = *it;
47+
std::cout << x << " ";
48+
++it;
49+
}
50+
std::cout << std::endl;
51+
}
52+
```
53+
* end[color ff0000]
54+
* begin[link begin.md]
55+
56+
### 出力
57+
58+
```
59+
6 7 8 9 10
60+
```
61+
62+
## バージョン
63+
### 言語
64+
- C++20
65+
66+
### 処理系
67+
- [Clang](/implementation.md#clang): 13.0.0 [mark verified]
68+
- [GCC](/implementation.md#gcc): 10.1.0 [mark verified]
69+
- [ICC](/implementation.md#icc): ?
70+
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 10 [mark verified]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# コンストラクタ
2+
* ranges[meta header]
3+
* std::ranges[meta namespace]
4+
* drop_while_view[meta class]
5+
* function[meta id-type]
6+
* cpp20[meta cpp]
7+
8+
```cpp
9+
drop_while_view()
10+
requires default_initializable<V> &&
11+
default_initializable<Pred> = default; // (1) C++20
12+
13+
constexpr explicit
14+
drop_while_view(V base, Pred pred); // (2) C++20
15+
```
16+
17+
## 概要
18+
19+
[`drop_while_view`](../drop_while_view.md)オブジェクトを構築する。
20+
21+
- (1) : デフォルト構築
22+
- (2) : 元となるviewと述語を指定して構築
23+
24+
## 効果
25+
26+
- (1) : `base_`と`pred_`をデフォルト構築する
27+
- (2) : `base_`を`std::move(base)`で、`pred_`を`std::move(pred)`で初期化する
28+
29+
## 例
30+
```cpp example
31+
#include <iostream>
32+
#include <ranges>
33+
#include <vector>
34+
35+
int main() {
36+
std::vector<int> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
37+
38+
std::ranges::drop_while_view view{vec, [](int x) { return x < 6; }};
39+
for (const auto& x : view) {
40+
std::cout << x << " ";
41+
}
42+
std::cout << std::endl;
43+
}
44+
```
45+
* drop_while_view[color ff0000]
46+
47+
### 出力
48+
```
49+
6 7 8 9 10
50+
```
51+
52+
## バージョン
53+
### 言語
54+
- C++20
55+
56+
### 処理系
57+
- [Clang](/implementation.md#clang): 13.0.0 [mark verified]
58+
- [GCC](/implementation.md#gcc): 10.1.0 [mark verified]
59+
- [ICC](/implementation.md#icc): ?
60+
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 10 [mark verified]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 R, class Pred>
10+
drop_while_view(R&&, Pred) -> drop_while_view<views::all_t<R>, Pred>;
11+
}
12+
```
13+
14+
## 概要
15+
16+
[`drop_while_view`](../drop_while_view.md)クラステンプレートの型推論補助。
17+
18+
この推論補助によって、元のRangeが暗黙的に[all view](../all.md)でラップされる。
19+
20+
## 例
21+
```cpp example
22+
#include <ranges>
23+
#include <vector>
24+
#include <concepts>
25+
26+
int main() {
27+
std::vector<int> vec = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
28+
auto pred = [](int x) { return x < 6; };
29+
30+
std::ranges::drop_while_view r1{vec, pred};
31+
static_assert(std::same_as<
32+
decltype(r1),
33+
std::ranges::drop_while_view<std::ranges::ref_view<std::vector<int>>, decltype(pred)>
34+
>);
35+
36+
std::ranges::drop_while_view r2{std::vector<int>{1, 2, 3, 4, 5}, pred};
37+
static_assert(std::same_as<
38+
decltype(r2),
39+
std::ranges::drop_while_view<std::ranges::owning_view<std::vector<int>>, decltype(pred)>
40+
>);
41+
}
42+
```
43+
44+
### 出力
45+
```
46+
```
47+
48+
## バージョン
49+
### 言語
50+
- C++20
51+
52+
### 処理系
53+
- [Clang](/implementation.md#clang): 13.0.0 [mark verified]
54+
- [GCC](/implementation.md#gcc): 10.1.0 [mark verified]
55+
- [ICC](/implementation.md#icc): ?
56+
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 10 [mark verified]

0 commit comments

Comments
 (0)