1 #ifndef OOKII_RANGE_HELPER_H_
4 #define OOKII_RANGE_HELPER_H_
10 namespace ookii::details
14 template<
typename T,
typename IteratorType>
17 using filter_function_type = std::function<bool(
const typename IteratorType::reference)>;
18 using transform_function_type = std::function<T(
const typename IteratorType::reference)>;
23 using iterator_concept = std::forward_iterator_tag;
25 using difference_type =
typename IteratorType::difference_type;
26 using pointer = std::remove_reference_t<value_type>*;
27 using reference = value_type&;
29 iterator(IteratorType it, IteratorType end, filter_function_type filter, transform_function_type transform)
38 iterator &operator++()
44 iterator operator++(
int)
46 iterator temp = *
this;
51 value_type operator*() const noexcept
53 return _transform(*_current);
56 bool operator==(
const iterator &other)
const noexcept
58 return _current == other._current;
62 void next_value(
bool check_current)
64 if (_current == _end || (check_current && (!_filter || _filter(*_current))))
73 }
while (_current != _end && _filter && !_filter(*_current));
76 IteratorType _current;
78 filter_function_type _filter;
79 transform_function_type _transform;
83 range_filter(IteratorType begin, IteratorType end, transform_function_type transform,
84 filter_function_type filter = {})
87 _transform{transform},
92 iterator begin() const noexcept
94 return iterator{_begin, _end, _filter, _transform};
97 iterator end() const noexcept
99 return iterator{_end, _end, _filter, _transform};
105 transform_function_type _transform;
106 filter_function_type _filter;