Skip to content

Commit

Permalink
Update split_view.h
Browse files Browse the repository at this point in the history
  • Loading branch information
lackhole committed Aug 23, 2024
1 parent d9b74c1 commit 5ddb140
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions include/preview/__ranges/views/split_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ class split_view : public view_interface<split_view<V, Pattern>> {
: end_(ranges::end(parent.base_)) {}

friend constexpr bool operator==(const iterator& x, const sentinel& y) {
using namespace preview::rel_ops;
return x.cur_ == y.end_ && !x.trailing_empty_;
return y.compare_with_iterator(x);
}

friend constexpr bool operator!=(const iterator& x, const sentinel& y) {
Expand All @@ -154,13 +153,18 @@ class split_view : public view_interface<split_view<V, Pattern>> {
}

private:
constexpr bool compare_with_iterator(const iterator& x) const {
using namespace preview::rel_ops;
return x.cur_ == end_ && !x.trailing_empty_;
}
sentinel_t<V> end_ = sentinel_t<V>();
};

split_view() = default;

constexpr explicit split_view(V base, Pattern pattern)
: base_(std::move(base)), pattern_(std::move(pattern)) {}
: base_(std::move(base))
, pattern_(std::move(pattern)) {}

template<typename R, std::enable_if_t<check_range<R>::value, int> = 0>
constexpr explicit split_view(R&& r, range_value_t<R> e)
Expand All @@ -186,14 +190,14 @@ class split_view : public view_interface<split_view<V, Pattern>> {
}

constexpr auto end() {
return end(common_range<V>{});
return end_impl(common_range<V>{});
}

private:
constexpr iterator end(std::true_type /* common_range<V> */) {
constexpr iterator end_impl(std::true_type /* common_range<V> */) {
return iterator{*this, ranges::end(base_), {}};
}
constexpr sentinel end(std::false_type /* common_range<V> */) {
constexpr sentinel end_impl(std::false_type /* common_range<V> */) {
return sentinel{*this};
}

Expand Down

0 comments on commit 5ddb140

Please sign in to comment.