transform_iterator.h 724 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // transform_iterator.h
  3. // stream
  4. //
  5. // Created by Sam Jaffe on 4/2/23.
  6. //
  7. #pragma once
  8. #include <iterator/proxy.h>
  9. #include <stream/forward.h>
  10. namespace stream::ranges {
  11. template <typename It, typename Proj>
  12. class transform_iterator : public proxy<It, transform_iterator<It, Proj>> {
  13. private:
  14. using super_t = proxy<It, transform_iterator<It, Proj>>;
  15. private:
  16. Proj projection_;
  17. public:
  18. transform_iterator() = default;
  19. transform_iterator(It iter, Proj projection)
  20. : super_t(std::move(iter)), projection_(projection) {}
  21. decltype(auto) dereference() const {
  22. return std::invoke(projection_, super_t::dereference());
  23. }
  24. };
  25. }
  26. MAKE_ITERATOR_FACADE_TYPEDEFS_T(stream::ranges::transform_iterator);