1 #ifndef TERMOX_COMMON_FILTER_ITERATOR_HPP
2 #define TERMOX_COMMON_FILTER_ITERATOR_HPP
9 template <
typename Iter,
typename Iter_end,
typename F>
12 using iterator_category = std::forward_iterator_tag;
13 using value_type =
typename Iter::value_type;
14 using difference_type =
typename Iter::difference_type;
15 using pointer =
typename Iter::pointer;
16 using reference =
typename Iter::reference;
22 : it_{it}, end_{end}, predicate_{std::forward<F>(predicate)}
24 this->increment_if_invalid();
41 [[nodiscard]]
auto operator*() const -> auto& {
return *it_; }
43 [[nodiscard]]
auto operator==(
Filter_iterator const& other)
const ->
bool
45 return it_ == other.it_;
48 [[nodiscard]]
auto operator!=(
Filter_iterator const& other)
const ->
bool
50 return it_ != other.it_;
54 [[nodiscard]]
auto operator==(T
const& other)
const ->
bool
60 [[nodiscard]]
auto operator!=(T
const& other)
const ->
bool
71 void increment_if_invalid()
73 while ((it_ != end_) && !predicate_(*it_))
81 }
while ((it_ != end_) && !predicate_(*it_));
operator++ skips underlying elements of it that do not satisfy predicate.
Definition: filter_iterator.hpp:10
Filter_iterator(Iter const it, Iter_end const end, F &&predicate)
Pass in the iterator to begin at, end iter, and predicate to test with.
Definition: filter_iterator.hpp:21