| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- //
- // iota_iterator.h
- // stream
- //
- // Created by Sam Jaffe on 4/6/23.
- //
- #pragma once
- #include <iterator/facade.h>
- #include <stream/forward.h>
- #include <stream/detail/traits.h>
- #include <stream/detail/macro.h>
- namespace stream::ranges {
- template <typename T, typename Bound>
- class iota_iterator : public facade<iota_iterator<T, Bound>,
- iterator::category::random_access> {
- public:
- using sentinal_type =
- std::conditional_t<std::is_same_v<T, Bound>, void, Bound>;
- iota_iterator() = default;
- iota_iterator(T value) : value_(value) {}
- T dereference() const { return value_; }
- void advance(std::ptrdiff_t off) { value_ += off; }
- std::ptrdiff_t distance_to(iota_iterator const & other) const {
- return other.value_ - value_;
- }
- SFINAE((detail::is_sized_sentinel_v<T, Bound>))
- friend bool operator-(Bound bound, iota_iterator const & self) {
- return bound - self.value_;
- }
- private:
- T value_;
- };
- }
- #include <stream/detail/undef.h>
|