iota_iterator.h 847 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 : public facade<iota_iterator<T, Bound>> {
  13. public:
  14. using sentinal_type = Bound;
  15. iota_iterator() = default;
  16. iota_iterator(T value, Bound bound) : value_(value), bound_(bound) {}
  17. T dereference() const { return value_; }
  18. void increment() { ++value_; }
  19. bool at_end() const { return value_ == bound_; }
  20. // Some weird bug in dependent template instantiation???
  21. bool equal_to(iota_iterator const & other) const {
  22. return value_ == other.value_;
  23. }
  24. std::ptrdiff_t distance_to(iota_iterator const & other) const {
  25. return other.value_ - value_;
  26. }
  27. private:
  28. T value_;
  29. Bound bound_;
  30. };
  31. }