From Jason Turner

[range.split.view]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpiefkhgju/{from.md → to.md} +52 -44
tmp/tmpiefkhgju/{from.md → to.md} RENAMED
@@ -1,88 +1,96 @@
1
  #### Class template `split_view` <a id="range.split.view">[[range.split.view]]</a>
2
 
3
  ``` cpp
4
  namespace std::ranges {
5
- template<auto> struct require-constant; // exposition only
6
-
7
- template<class R>
8
- concept tiny-range = // exposition only
9
- sized_range<R> &&
10
- requires { typename require-constant<remove_reference_t<R>::size()>; } &&
11
- (remove_reference_t<R>::size() <= 1);
12
-
13
- template<input_range V, forward_range Pattern>
14
  requires view<V> && view<Pattern> &&
15
- indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> &&
16
- (forward_range<V> || tiny-range<Pattern>)
17
  class split_view : public view_interface<split_view<V, Pattern>> {
18
  private:
19
  V base_ = V(); // exposition only
20
  Pattern pattern_ = Pattern(); // exposition only
21
- iterator_t<V> current_ = iterator_t<V>(); // exposition only, present only if !forward_range<V>
22
- // [range.split.outer], class template split_view::outer-iterator
23
- template<bool> struct outer-iterator; // exposition only
24
- // [range.split.inner], class template split_view::inner-iterator
25
- template<bool> struct inner-iterator; // exposition only
 
 
26
  public:
27
- split_view() = default;
28
- constexpr split_view(V base, Pattern pattern);
 
29
 
30
- template<input_range R>
31
  requires constructible_from<V, views::all_t<R>> &&
32
  constructible_from<Pattern, single_view<range_value_t<R>>>
33
- constexpr split_view(R&& r, range_value_t<R> e);
34
 
35
  constexpr V base() const & requires copy_constructible<V> { return base_; }
36
  constexpr V base() && { return std::move(base_); }
37
 
38
- constexpr auto begin() {
39
- if constexpr (forward_range<V>)
40
- return outer-iterator<simple-view<V>>{*this, ranges::begin(base_)};
41
- else {
42
- current_ = ranges::begin(base_);
43
- return outer-iterator<false>{*this};
44
- }
45
- }
46
 
47
- constexpr auto begin() const requires forward_range<V> && forward_range<const V> {
48
- return outer-iterator<true>{*this, ranges::begin(base_)};
 
 
 
49
  }
50
-
51
- constexpr auto end() requires forward_range<V> && common_range<V> {
52
- return outer-iterator<simple-view<V>>{*this, ranges::end(base_)};
53
  }
54
 
55
- constexpr auto end() const {
56
- if constexpr (forward_range<V> && forward_range<const V> && common_range<const V>)
57
- return outer-iterator<true>{*this, ranges::end(base_)};
58
- else
59
- return default_sentinel;
60
- }
61
  };
62
 
63
  template<class R, class P>
64
  split_view(R&&, P&&) -> split_view<views::all_t<R>, views::all_t<P>>;
65
 
66
- template<input_range R>
67
  split_view(R&&, range_value_t<R>)
68
  -> split_view<views::all_t<R>, single_view<range_value_t<R>>>;
69
  }
70
  ```
71
 
72
  ``` cpp
73
- constexpr split_view(V base, Pattern pattern);
74
  ```
75
 
76
  *Effects:* Initializes *base\_* with `std::move(base)`, and *pattern\_*
77
  with `std::move(pattern)`.
78
 
79
  ``` cpp
80
- template<input_range R>
81
  requires constructible_from<V, views::all_t<R>> &&
82
  constructible_from<Pattern, single_view<range_value_t<R>>>
83
- constexpr split_view(R&& r, range_value_t<R> e);
84
  ```
85
 
86
  *Effects:* Initializes *base\_* with `views::all(std::forward<R>(r))`,
87
- and *pattern\_* with `single_view{std::move(e)}`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
 
1
  #### Class template `split_view` <a id="range.split.view">[[range.split.view]]</a>
2
 
3
  ``` cpp
4
  namespace std::ranges {
5
+ template<forward_range V, forward_range Pattern>
 
 
 
 
 
 
 
 
6
  requires view<V> && view<Pattern> &&
7
+ indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to>
 
8
  class split_view : public view_interface<split_view<V, Pattern>> {
9
  private:
10
  V base_ = V(); // exposition only
11
  Pattern pattern_ = Pattern(); // exposition only
12
+
13
+ // [range.split.iterator], class split_view::iterator
14
+ struct iterator; // exposition only
15
+
16
+ // [range.split.sentinel], class split_view::sentinel
17
+ struct sentinel; // exposition only
18
+
19
  public:
20
+ split_view()
21
+ requires default_initializable<V> && default_initializable<Pattern> = default;
22
+ constexpr explicit split_view(V base, Pattern pattern);
23
 
24
+ template<forward_range R>
25
  requires constructible_from<V, views::all_t<R>> &&
26
  constructible_from<Pattern, single_view<range_value_t<R>>>
27
+ constexpr explicit split_view(R&& r, range_value_t<R> e);
28
 
29
  constexpr V base() const & requires copy_constructible<V> { return base_; }
30
  constexpr V base() && { return std::move(base_); }
31
 
32
+ constexpr iterator begin();
 
 
 
 
 
 
 
33
 
34
+ constexpr auto end() {
35
+ if constexpr (common_range<V>) {
36
+ return iterator{*this, ranges::end(base_), {}};
37
+ } else {
38
+ return sentinel{*this};
39
  }
 
 
 
40
  }
41
 
42
+ constexpr subrange<iterator_t<V>> find-next(iterator_t<V>); // exposition only
 
 
 
 
 
43
  };
44
 
45
  template<class R, class P>
46
  split_view(R&&, P&&) -> split_view<views::all_t<R>, views::all_t<P>>;
47
 
48
+ template<forward_range R>
49
  split_view(R&&, range_value_t<R>)
50
  -> split_view<views::all_t<R>, single_view<range_value_t<R>>>;
51
  }
52
  ```
53
 
54
  ``` cpp
55
+ constexpr explicit split_view(V base, Pattern pattern);
56
  ```
57
 
58
  *Effects:* Initializes *base\_* with `std::move(base)`, and *pattern\_*
59
  with `std::move(pattern)`.
60
 
61
  ``` cpp
62
+ template<forward_range R>
63
  requires constructible_from<V, views::all_t<R>> &&
64
  constructible_from<Pattern, single_view<range_value_t<R>>>
65
+ constexpr explicit split_view(R&& r, range_value_t<R> e);
66
  ```
67
 
68
  *Effects:* Initializes *base\_* with `views::all(std::forward<R>(r))`,
69
+ and *pattern\_* with `views::single(std::move(e))`.
70
+
71
+ ``` cpp
72
+ constexpr iterator begin();
73
+ ```
74
+
75
+ *Returns:*
76
+ `{*this, ranges::begin(`*`base_`*`), `*`find-next`*`(ranges::begin(`*`base_`*`))}`.
77
+
78
+ *Remarks:* In order to provide the amortized constant time complexity
79
+ required by the `range` concept, this function caches the result within
80
+ the `split_view` for use on subsequent calls.
81
+
82
+ ``` cpp
83
+ constexpr subrange<iterator_t<V>> find-next(iterator_t<V> it);
84
+ ```
85
+
86
+ *Effects:* Equivalent to:
87
+
88
+ ``` cpp
89
+ auto [b, e] = ranges::search(subrange(it, ranges::end(base_)), pattern_);
90
+ if (b != ranges::end(base_) && ranges::empty(pattern_)) {
91
+ ++b;
92
+ ++e;
93
+ }
94
+ return {b, e};
95
+ ```
96