tmp/tmpcf155e7b/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### Class template `take_view` <a id="range.take.view">[[range.take.view]]</a>
|
| 2 |
+
|
| 3 |
+
``` cpp
|
| 4 |
+
namespace std::ranges {
|
| 5 |
+
template<view V>
|
| 6 |
+
class take_view : public view_interface<take_view<V>> {
|
| 7 |
+
private:
|
| 8 |
+
V base_ = V(); // exposition only
|
| 9 |
+
range_difference_t<V> count_ = 0; // exposition only
|
| 10 |
+
// [range.take.sentinel], class template take_view::sentinel
|
| 11 |
+
template<bool> struct sentinel; // exposition only
|
| 12 |
+
public:
|
| 13 |
+
take_view() = default;
|
| 14 |
+
constexpr take_view(V base, range_difference_t<V> count);
|
| 15 |
+
|
| 16 |
+
constexpr V base() const& requires copy_constructible<V> { return base_; }
|
| 17 |
+
constexpr V base() && { return std::move(base_); }
|
| 18 |
+
|
| 19 |
+
constexpr auto begin() requires (!simple-view<V>) {
|
| 20 |
+
if constexpr (sized_range<V>) {
|
| 21 |
+
if constexpr (random_access_range<V>)
|
| 22 |
+
return ranges::begin(base_);
|
| 23 |
+
else {
|
| 24 |
+
auto sz = size();
|
| 25 |
+
return counted_iterator{ranges::begin(base_), sz};
|
| 26 |
+
}
|
| 27 |
+
} else
|
| 28 |
+
return counted_iterator{ranges::begin(base_), count_};
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
constexpr auto begin() const requires range<const V> {
|
| 32 |
+
if constexpr (sized_range<const V>) {
|
| 33 |
+
if constexpr (random_access_range<const V>)
|
| 34 |
+
return ranges::begin(base_);
|
| 35 |
+
else {
|
| 36 |
+
auto sz = size();
|
| 37 |
+
return counted_iterator{ranges::begin(base_), sz};
|
| 38 |
+
}
|
| 39 |
+
} else
|
| 40 |
+
return counted_iterator{ranges::begin(base_), count_};
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
constexpr auto end() requires (!simple-view<V>) {
|
| 44 |
+
if constexpr (sized_range<V>) {
|
| 45 |
+
if constexpr (random_access_range<V>)
|
| 46 |
+
return ranges::begin(base_) + size();
|
| 47 |
+
else
|
| 48 |
+
return default_sentinel;
|
| 49 |
+
} else
|
| 50 |
+
return sentinel<false>{ranges::end(base_)};
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
constexpr auto end() const requires range<const V> {
|
| 54 |
+
if constexpr (sized_range<const V>) {
|
| 55 |
+
if constexpr (random_access_range<const V>)
|
| 56 |
+
return ranges::begin(base_) + size();
|
| 57 |
+
else
|
| 58 |
+
return default_sentinel;
|
| 59 |
+
} else
|
| 60 |
+
return sentinel<true>{ranges::end(base_)};
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
constexpr auto size() requires sized_range<V> {
|
| 64 |
+
auto n = ranges::size(base_);
|
| 65 |
+
return ranges::min(n, static_cast<decltype(n)>(count_));
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
constexpr auto size() const requires sized_range<const V> {
|
| 69 |
+
auto n = ranges::size(base_);
|
| 70 |
+
return ranges::min(n, static_cast<decltype(n)>(count_));
|
| 71 |
+
}
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
template<range R>
|
| 75 |
+
take_view(R&&, range_difference_t<R>)
|
| 76 |
+
-> take_view<views::all_t<R>>;
|
| 77 |
+
}
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
``` cpp
|
| 81 |
+
constexpr take_view(V base, range_difference_t<V> count);
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
*Effects:* Initializes *base\_* with `std::move(base)` and *count\_*
|
| 85 |
+
with `count`.
|
| 86 |
+
|