From Jason Turner

[range.common.view]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpuyxg9169/{from.md → to.md} +76 -0
tmp/tmpuyxg9169/{from.md → to.md} RENAMED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #### Class template `common_view` <a id="range.common.view">[[range.common.view]]</a>
2
+
3
+ ``` cpp
4
+ namespace std::ranges {
5
+ template<view V>
6
+ requires (!common_range<V> && copyable<iterator_t<V>>)
7
+ class common_view : public view_interface<common_view<V>> {
8
+ private:
9
+ V base_ = V(); // exposition only
10
+ public:
11
+ common_view() = default;
12
+
13
+ constexpr explicit common_view(V r);
14
+
15
+ template<viewable_range R>
16
+ requires (!common_range<R> && constructible_from<V, views::all_t<R>>)
17
+ constexpr explicit common_view(R&& r);
18
+
19
+ constexpr V base() const& requires copy_constructible<V> { return base_; }
20
+ constexpr V base() && { return std::move(base_); }
21
+
22
+ constexpr auto begin() {
23
+ if constexpr (random_access_range<V> && sized_range<V>)
24
+ return ranges::begin(base_);
25
+ else
26
+ return common_iterator<iterator_t<V>, sentinel_t<V>>(ranges::begin(base_));
27
+ }
28
+
29
+ constexpr auto begin() const requires range<const V> {
30
+ if constexpr (random_access_range<const V> && sized_range<const V>)
31
+ return ranges::begin(base_);
32
+ else
33
+ return common_iterator<iterator_t<const V>, sentinel_t<const V>>(ranges::begin(base_));
34
+ }
35
+
36
+ constexpr auto end() {
37
+ if constexpr (random_access_range<V> && sized_range<V>)
38
+ return ranges::begin(base_) + ranges::size(base_);
39
+ else
40
+ return common_iterator<iterator_t<V>, sentinel_t<V>>(ranges::end(base_));
41
+ }
42
+
43
+ constexpr auto end() const requires range<const V> {
44
+ if constexpr (random_access_range<const V> && sized_range<const V>)
45
+ return ranges::begin(base_) + ranges::size(base_);
46
+ else
47
+ return common_iterator<iterator_t<const V>, sentinel_t<const V>>(ranges::end(base_));
48
+ }
49
+
50
+ constexpr auto size() requires sized_range<V> {
51
+ return ranges::size(base_);
52
+ }
53
+ constexpr auto size() const requires sized_range<const V> {
54
+ return ranges::size(base_);
55
+ }
56
+ };
57
+
58
+ template<class R>
59
+ common_view(R&&) -> common_view<views::all_t<R>>;
60
+ }
61
+ ```
62
+
63
+ ``` cpp
64
+ constexpr explicit common_view(V base);
65
+ ```
66
+
67
+ *Effects:* Initializes *base\_* with `std::move(base)`.
68
+
69
+ ``` cpp
70
+ template<viewable_range R>
71
+ requires (!common_range<R> && constructible_from<V, views::all_t<R>>)
72
+ constexpr explicit common_view(R&& r);
73
+ ```
74
+
75
+ *Effects:* Initializes *base\_* with `views::all(std::forward<R>(r))`.
76
+