Skip to content

Commit

Permalink
sentinel_forに対応
Browse files Browse the repository at this point in the history
  • Loading branch information
acd1034 committed Sep 17, 2022
1 parent 0205c08 commit 8a06277
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/ns/enumerate_view.hpp
Expand Up @@ -36,6 +36,9 @@ namespace ns {
constexpr iterator(std::ranges::iterator_t<View> current, std::size_t count)
: current_(std::move(current)), count_(std::move(count)) {}

constexpr const std::ranges::iterator_t<View>& base() const& noexcept { return current_; }
constexpr std::ranges::iterator_t<View> base() && { return std::move(current_); }

constexpr std::pair<std::size_t, std::ranges::range_reference_t<View>> //
operator*() const {
return {count_, *current_};
Expand All @@ -57,6 +60,13 @@ namespace ns {
std::ranges::sentinel_t<View> end_ = std::ranges::sentinel_t<View>();

public:
sentinel() requires std::default_initializable<std::ranges::sentinel_t<View>>
= default;
constexpr explicit sentinel(std::ranges::sentinel_t<View> end) : end_(std::move(end)) {}

friend constexpr bool operator==(const iterator& x, const sentinel& y) requires
std::sentinel_for<std::ranges::sentinel_t<View>, std::ranges::iterator_t<View>> {
return x.base() == y.end_;
}
};
} // namespace ns
1 change: 1 addition & 0 deletions tests/enumerate_view/enumerate_view.cpp
Expand Up @@ -46,5 +46,6 @@ static_assert(not std::ranges::forward_range<test_view<int>>);
using testing_view = ns::enumerate_view<test_view<int>>;
// まだ動かない
// static_assert(std::input_or_output_iterator<std::ranges::iterator_t<testing_view>>);
// static_assert(std::sentinel_for<std::ranges::sentinel_t<testing_view>, std::ranges::iterator_t<testing_view>>);

// TEST_CASE("enumerate_view", "[enumerate_view]") {}

0 comments on commit 8a06277

Please sign in to comment.