iota.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // iota.h
  3. // stream
  4. //
  5. // Created by Sam Jaffe on 3/29/23.
  6. //
  7. #pragma once
  8. #include <stream/forward.h>
  9. #include <stream/iterator/iota_iterator.h>
  10. #include <stream/view/interface.h>
  11. #include <stream/detail/macro.h>
  12. namespace stream::ranges {
  13. template <typename T, typename Bound>
  14. struct iota_view : public view_interface<iota_view<T, Bound>,
  15. iota_iterator<T, Bound>, Bound> {
  16. private:
  17. T value_;
  18. Bound bound_;
  19. public:
  20. iota_view(T value, Bound bound) : value_(value), bound_(bound) {}
  21. auto begin() const { return iota_iterator<T, Bound>(value_); }
  22. auto end() const { return bound_; }
  23. };
  24. template <typename T>
  25. struct iota_view<T, T>
  26. : public view_interface<iota_view<T, T>, iota_iterator<T, T>> {
  27. private:
  28. T value_;
  29. T bound_;
  30. public:
  31. iota_view(T value, T bound) : value_(value), bound_(bound) {}
  32. auto begin() const { return iota_iterator<T, T>(value_); }
  33. auto end() const { return iota_iterator<T, T>(bound_); }
  34. };
  35. }
  36. namespace stream::ranges::views {
  37. template <typename T, typename Bound> auto iota(T value, Bound bound) {
  38. return iota_view(value, bound);
  39. }
  40. }
  41. MAKE_ITERATOR_FACADE_TYPEDEFS_T(stream::ranges::iota_iterator);
  42. #include <stream/detail/undef.h>