Skip to content

Commit 30dd29c

Browse files
committed
join_with_view : メンバ関数を追加 #713
1 parent a5b62f3 commit 30dd29c

File tree

6 files changed

+327
-6
lines changed

6 files changed

+327
-6
lines changed

reference/ranges/join_with_view.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace std::ranges {
4343
4444
## 効果
4545
46-
- (2): 式`views::join_with(E, F)`の効果は[`join_with_view{E, F}`](join_with_view/op_constructor.md.nolink)と等しい。
46+
- (2): 式`views::join_with(E, F)`の効果は[`join_with_view{E, F}`](join_with_view/op_constructor.md)と等しい。
4747
4848
## 備考
4949
@@ -66,10 +66,10 @@ namespace std::ranges {
6666

6767
| 名前 | 説明 | 対応バージョン |
6868
|--------------------------------------------------|----------------------------------|----------------|
69-
| [`(constructor)`](join_with_view/op_constructor.md.nolink) | コンストラクタ | C++23 |
70-
| [`base`](join_with_view/base.md.nolink) | `V`の参照を取得する | C++23 |
71-
| [`begin`](join_with_view/begin.md.nolink) | 先頭を指すイテレータを取得する | C++23 |
72-
| [`end`](join_with_view/end.md.nolink) | 番兵を取得する | C++23 |
69+
| [`(constructor)`](join_with_view/op_constructor.md) | コンストラクタ | C++23 |
70+
| [`base`](join_with_view/base.md) | `V`の参照を取得する | C++23 |
71+
| [`begin`](join_with_view/begin.md) | 先頭を指すイテレータを取得する | C++23 |
72+
| [`end`](join_with_view/end.md) | 番兵を取得する | C++23 |
7373

7474
## 継承しているメンバ関数
7575

@@ -86,7 +86,7 @@ namespace std::ranges {
8686

8787
| 名前 | 説明 | 対応バージョン |
8888
|-------------------------------------------------------|------------------------------|----------------|
89-
| [`(deduction_guide)`](join_with_view/op_deduction_guide.md.nolink) | クラステンプレートの推論補助 | C++23 |
89+
| [`(deduction_guide)`](join_with_view/op_deduction_guide.md) | クラステンプレートの推論補助 | C++23 |
9090

9191
##
9292
```cpp example
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# base
2+
* ranges[meta header]
3+
* std::ranges[meta namespace]
4+
* join_with_view[meta class]
5+
* function[meta id-type]
6+
* cpp23[meta cpp]
7+
8+
```cpp
9+
constexpr V base() const &
10+
requires copy_constructible<V>; // (1) C++23
11+
12+
constexpr V base() &&; // (2) C++23
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 <string>
32+
#include <iostream>
33+
34+
int main() {
35+
using std::ranges::view;
36+
37+
std::vector<std::string> words = {"hello", "world", "join"};
38+
std::string delimiter = "-";
39+
40+
std::ranges::join_with_view r{words, delimiter};
41+
42+
// (1) コピーして取得
43+
view auto b1 = r.base();
44+
45+
// (2) ムーブして取得
46+
view auto b2 = std::move(r).base();
47+
48+
// 得られるのは元のRangeではなく、あくまでview
49+
static_assert(not std::same_as<decltype(b1), std::vector<std::string>>);
50+
static_assert( std::same_as<decltype(b1), std::ranges::ref_view<std::vector<std::string>>>);
51+
static_assert( std::same_as<decltype(b2), std::ranges::ref_view<std::vector<std::string>>>);
52+
}
53+
```
54+
* base[color ff0000]
55+
56+
### 出力
57+
58+
```
59+
```
60+
61+
## バージョン
62+
### 言語
63+
- C++23
64+
65+
### 処理系
66+
- [Clang](/implementation.md#clang): ??
67+
- [GCC](/implementation.md#gcc): 13.2 [mark verified]
68+
- [ICC](/implementation.md#icc): ??
69+
- [Visual C++](/implementation.md#visual_cpp): ??
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# begin
2+
* ranges[meta header]
3+
* std::ranges[meta namespace]
4+
* join_with_view[meta class]
5+
* function[meta id-type]
6+
* cpp23[meta cpp]
7+
8+
```cpp
9+
constexpr auto begin()
10+
requires (!simple-view<V>); // (1) C++23
11+
12+
constexpr auto begin() const
13+
requires range<const V> &&
14+
input_range<range_reference_t<const V>> &&
15+
range<const Pattern>; // (2) C++23
16+
```
17+
18+
## 概要
19+
20+
`view`の先頭要素を指すイテレータを取得する。
21+
22+
## 戻り値
23+
- (1), (2) : `join_with_view`の先頭を指すイテレータを返す。外側のRangeが空でない場合、最初の内側Rangeの先頭要素を指す。外側のRangeが空の場合、[`end()`](end.md)と等価なイテレータを返す。
24+
25+
## 例
26+
27+
```cpp example
28+
#include <ranges>
29+
#include <vector>
30+
#include <string>
31+
#include <iostream>
32+
33+
int main() {
34+
std::vector<std::string> words = {"hello", "world", "join"};
35+
std::string delimiter = "-";
36+
37+
std::ranges::join_with_view r{words, delimiter};
38+
39+
auto it = r.begin();
40+
41+
char x = *it;
42+
std::cout << x << '\n';
43+
}
44+
```
45+
* begin[color ff0000]
46+
47+
### 出力
48+
49+
```
50+
h
51+
```
52+
53+
## バージョン
54+
### 言語
55+
- C++23
56+
57+
### 処理系
58+
- [Clang](/implementation.md#clang): ??
59+
- [GCC](/implementation.md#gcc): 13.2 [mark verified]
60+
- [ICC](/implementation.md#icc): ??
61+
- [Visual C++](/implementation.md#visual_cpp): ??
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# end
2+
* ranges[meta header]
3+
* std::ranges[meta namespace]
4+
* join_with_view[meta class]
5+
* function[meta id-type]
6+
* cpp23[meta cpp]
7+
8+
```cpp
9+
constexpr auto end()
10+
requires (!simple-view<V>); // (1) C++23
11+
12+
constexpr auto end() const
13+
requires range<const V> &&
14+
input_range<range_reference_t<const V>> &&
15+
range<const Pattern>; // (2) C++23
16+
```
17+
18+
## 概要
19+
番兵を取得する。
20+
21+
## 戻り値
22+
- (1), (2) : `join_with_view`の番兵を返す
23+
24+
## 例
25+
26+
```cpp example
27+
#include <ranges>
28+
#include <vector>
29+
#include <string>
30+
#include <iostream>
31+
32+
int main() {
33+
std::vector<std::string> words = {"hello", "world", "join"};
34+
std::string delimiter = "-";
35+
36+
std::ranges::join_with_view r{words, delimiter};
37+
38+
auto it = r.begin();
39+
auto end_it = r.end();
40+
while (it != end_it) {
41+
char x = *it;
42+
std::cout << x;
43+
++it;
44+
}
45+
std::cout << std::endl;
46+
}
47+
```
48+
* end[color ff0000]
49+
* begin[link begin.md]
50+
51+
### 出力
52+
53+
```
54+
hello-world-join
55+
```
56+
57+
## バージョン
58+
### 言語
59+
- C++23
60+
61+
### 処理系
62+
- [Clang](/implementation.md#clang): ??
63+
- [GCC](/implementation.md#gcc): 13.2 [mark verified]
64+
- [ICC](/implementation.md#icc): ??
65+
- [Visual C++](/implementation.md#visual_cpp): ??
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+
* join_with_view[meta class]
5+
* function[meta id-type]
6+
* cpp23[meta cpp]
7+
8+
```cpp
9+
join_with_view()
10+
requires default_initializable<V> && default_initializable<Pattern> = default; // (1) C++23
11+
12+
constexpr explicit join_with_view(V base, Pattern pattern); // (2) C++23
13+
```
14+
15+
## 概要
16+
17+
[`join_with_view`](../join_with_view.md)オブジェクトを構築する。
18+
19+
- (1) : デフォルト構築
20+
- (2) : 元となるviewとデリミタパターンを指定して構築
21+
22+
## 効果
23+
24+
- (1) : `base_`と`pattern_`をデフォルト構築する
25+
- (2) : `base_`を`std::move(base)`で、`pattern_`を`std::move(pattern)`で初期化する
26+
27+
## 例
28+
```cpp example
29+
#include <iostream>
30+
#include <ranges>
31+
#include <vector>
32+
#include <string>
33+
34+
int main() {
35+
std::vector<std::string> words = {"hello", "world", "join"};
36+
std::string delimiter = "-";
37+
38+
std::ranges::join_with_view view{words, delimiter};
39+
for (char c : view) {
40+
std::cout << c;
41+
}
42+
std::cout << std::endl;
43+
}
44+
```
45+
* join_with_view[color ff0000]
46+
47+
### 出力
48+
```
49+
hello-world-join
50+
```
51+
52+
## バージョン
53+
### 言語
54+
- C++23
55+
56+
### 処理系
57+
- [Clang](/implementation.md#clang): ??
58+
- [GCC](/implementation.md#gcc): 13.2 [mark verified]
59+
- [ICC](/implementation.md#icc): ??
60+
- [Visual C++](/implementation.md#visual_cpp): ??
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# 推論補助
2+
* ranges[meta header]
3+
* std::ranges[meta namespace]
4+
* function[meta id-type]
5+
* cpp23[meta cpp]
6+
7+
```cpp
8+
namespace std::ranges {
9+
template<class R, class P>
10+
join_with_view(R&&, P&&) -> join_with_view<views::all_t<R>, views::all_t<P>>;
11+
}
12+
```
13+
14+
## 概要
15+
16+
[`join_with_view`](../join_with_view.md)クラステンプレートの型推論補助。
17+
18+
この推論補助によって、元のRangeとパターンが暗黙的に[all view](../all.md)でラップされる。
19+
20+
## 例
21+
```cpp example
22+
#include <ranges>
23+
#include <vector>
24+
#include <string>
25+
#include <concepts>
26+
27+
int main() {
28+
std::vector<std::string> words = {"hello", "world", "join"};
29+
std::string delimiter = "-";
30+
31+
std::ranges::join_with_view r1{words, delimiter};
32+
static_assert(std::same_as<
33+
decltype(r1),
34+
std::ranges::join_with_view<
35+
std::ranges::ref_view<std::vector<std::string>>,
36+
std::ranges::ref_view<std::string>
37+
>
38+
>);
39+
40+
std::ranges::join_with_view r2{
41+
std::vector<std::string>{"a", "b", "c"},
42+
std::string{"--"}
43+
};
44+
static_assert(std::same_as<
45+
decltype(r2),
46+
std::ranges::join_with_view<
47+
std::ranges::owning_view<std::vector<std::string>>,
48+
std::ranges::owning_view<std::string>
49+
>
50+
>);
51+
}
52+
```
53+
54+
### 出力
55+
```
56+
```
57+
58+
## バージョン
59+
### 言語
60+
- C++23
61+
62+
### 処理系
63+
- [Clang](/implementation.md#clang): ??
64+
- [GCC](/implementation.md#gcc): 13.2 [mark verified]
65+
- [ICC](/implementation.md#icc): ??
66+
- [Visual C++](/implementation.md#visual_cpp): ??

0 commit comments

Comments
 (0)