iota_iterator.h 880 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // iota_iterator.h
  3. // stream
  4. //
  5. // Created by Sam Jaffe on 4/6/23.
  6. //
  7. #pragma once
  8. #include <iterator/facade.h>
  9. #include <stream/forward.h>
  10. namespace stream::ranges {
  11. template <typename T, typename Bound>
  12. class iota_iterator
  13. : public facade<iota_iterator<T, Bound>, iterator::category::forward> {
  14. public:
  15. using sentinal_type = Bound;
  16. iota_iterator() = default;
  17. iota_iterator(T value, Bound bound) : value_(value), bound_(bound) {}
  18. T dereference() const { return value_; }
  19. void increment() { ++value_; }
  20. bool at_end() const { return value_ == bound_; }
  21. // Some weird bug in dependent template instantiation???
  22. bool equal_to(iota_iterator const & other) const {
  23. return value_ == other.value_;
  24. }
  25. std::ptrdiff_t distance_to(iota_iterator const & other) const {
  26. return other.value_ - value_;
  27. }
  28. private:
  29. T value_;
  30. Bound bound_;
  31. };
  32. }