1 #ifndef TERMOX_COMMON_TRANSFORM_ITERATOR_HPP
2 #define TERMOX_COMMON_TRANSFORM_ITERATOR_HPP
14 template <
typename Iter,
typename Map_fn>
17 using iterator_category =
typename Iter::iterator_category;
18 using difference_type =
typename Iter::difference_type;
19 using reference = std::invoke_result_t<Map_fn, typename Iter::reference>;
20 using value_type = std::remove_reference_t<reference>;
21 using pointer = value_type*;
25 : it_{it}, map_fn_{std::move(map_fn)}
48 return {it_++, map_fn_};
59 return {it_ + n, map_fn_};
62 [[nodiscard]]
friend auto operator+(difference_type n,
66 return {n + it.underlying(), it.map_fn_};
77 return {it_--, map_fn_};
89 return it_ - other.it_;
94 return {it_ - n, map_fn_};
97 [[nodiscard]]
auto operator*()
const -> reference {
return map_fn_(*it_); }
101 return it_ == other.it_;
106 return it_ != other.it_;
109 template <
typename T>
110 [[nodiscard]]
auto operator==(T
const& other)
const ->
bool
115 template <
typename T>
116 [[nodiscard]]
auto operator!=(T
const& other)
const ->
bool
121 [[nodiscard]]
auto underlying()
const -> Iter {
return it_; }
128 template <
typename Iter,
typename Map_fn>
132 return a.underlying() < b.underlying();
135 template <
typename Iter,
typename Map_fn>
136 [[nodiscard]]
auto operator<=(Transform_iterator<Iter, Map_fn>
const& a,
137 Transform_iterator<Iter, Map_fn>
const& b) ->
bool
139 return a.underlying() <= b.underlying();
142 template <
typename Iter,
typename Map_fn>
143 [[nodiscard]]
auto operator>(Transform_iterator<Iter, Map_fn>
const& a,
144 Transform_iterator<Iter, Map_fn>
const& b) ->
bool
146 return a.underlying() > b.underlying();
149 template <
typename Iter,
typename Map_fn>
150 [[nodiscard]]
auto operator>=(Transform_iterator<Iter, Map_fn>
const& a,
151 Transform_iterator<Iter, Map_fn>
const& b) ->
bool
153 return a.underlying() >= b.underlying();