libzypp 17.38.7
zyppng::FilterIterator< Pred, Base > Class Template Reference

A simple forward iterator that filters a base range according to a predicate. More...

#include <zypp-core/ng/base/iterators.h>

Public Types

using iterator_category = std::forward_iterator_tag
using value_type = typename std::iterator_traits<Base>::value_type
using difference_type = typename std::iterator_traits<Base>::difference_type
using pointer = typename std::iterator_traits<Base>::pointer
using reference = typename std::iterator_traits<Base>::reference

Public Member Functions

 FilterIterator ()=default
 Default constructor.
 FilterIterator (Pred p, Base it, Base end)
 Constructs a FilterIterator.
reference operator* () const
 Dereference operator.
pointer operator-> () const
 Arrow operator.
FilterIteratoroperator++ ()
 Pre-increment operator.
FilterIterator operator++ (int)
 Post-increment operator.
bool operator== (const FilterIterator &other) const
 Equality comparison.
bool operator!= (const FilterIterator &other) const
 Inequality comparison.
Base const & base () const
 Returns the underlying base iterator at its current position.

Private Member Functions

void satisfy_predicate ()
 Advances the internal iterator until the predicate is met or _end is reached.

Private Attributes

Pred _pred
Base _it
Base _end

Detailed Description

template<class Pred, class Base>
class zyppng::FilterIterator< Pred, Base >

A simple forward iterator that filters a base range according to a predicate.

This class serves as a C++17 compatible drop-in replacement for boost::filter_iterator. It is designed as a stopgap measure to eliminate Boost dependencies in the Next-Generation (NG) layer until full C++20 std::ranges or a polyfill like range-v3 is integrated.

The iterator takes a predicate (which returns true for elements that should be included) and a pair of iterators (it and end) representing the underlying sequence. Whenever incremented, it automatically advances until the predicate is satisfied or the end boundary is reached.

Note
Because this is a C++17 forward iterator and not a C++20 sentinel-based view, it must carry the _end iterator internally, making it a "fat iterator".
Template Parameters
PredA callable that takes a value of the base sequence and returns bool.
BaseThe underlying forward iterator type.

Definition at line 39 of file iterators.h.

Member Typedef Documentation

◆ iterator_category

template<class Pred, class Base>
using zyppng::FilterIterator< Pred, Base >::iterator_category = std::forward_iterator_tag

Definition at line 41 of file iterators.h.

◆ value_type

template<class Pred, class Base>
using zyppng::FilterIterator< Pred, Base >::value_type = typename std::iterator_traits<Base>::value_type

Definition at line 42 of file iterators.h.

◆ difference_type

template<class Pred, class Base>
using zyppng::FilterIterator< Pred, Base >::difference_type = typename std::iterator_traits<Base>::difference_type

Definition at line 43 of file iterators.h.

◆ pointer

template<class Pred, class Base>
using zyppng::FilterIterator< Pred, Base >::pointer = typename std::iterator_traits<Base>::pointer

Definition at line 44 of file iterators.h.

◆ reference

template<class Pred, class Base>
using zyppng::FilterIterator< Pred, Base >::reference = typename std::iterator_traits<Base>::reference

Definition at line 45 of file iterators.h.

Constructor & Destructor Documentation

◆ FilterIterator() [1/2]

template<class Pred, class Base>
zyppng::FilterIterator< Pred, Base >::FilterIterator ( )
default

Default constructor.

Creates an invalid/end iterator.

◆ FilterIterator() [2/2]

template<class Pred, class Base>
zyppng::FilterIterator< Pred, Base >::FilterIterator ( Pred p,
Base it,
Base end )
inline

Constructs a FilterIterator.

Parameters
pThe predicate used to filter elements.
itThe start of the base sequence.
endThe end of the base sequence.

Definition at line 56 of file iterators.h.

Member Function Documentation

◆ operator*()

template<class Pred, class Base>
reference zyppng::FilterIterator< Pred, Base >::operator* ( ) const
inline

Dereference operator.

Definition at line 63 of file iterators.h.

◆ operator->()

template<class Pred, class Base>
pointer zyppng::FilterIterator< Pred, Base >::operator-> ( ) const
inline

Arrow operator.

Definition at line 66 of file iterators.h.

◆ operator++() [1/2]

template<class Pred, class Base>
FilterIterator & zyppng::FilterIterator< Pred, Base >::operator++ ( )
inline

Pre-increment operator.

Advances to the next element satisfying the predicate.

Definition at line 69 of file iterators.h.

◆ operator++() [2/2]

template<class Pred, class Base>
FilterIterator zyppng::FilterIterator< Pred, Base >::operator++ ( int )
inline

Post-increment operator.

Definition at line 76 of file iterators.h.

◆ operator==()

template<class Pred, class Base>
bool zyppng::FilterIterator< Pred, Base >::operator== ( const FilterIterator< Pred, Base > & other) const
inline

Equality comparison.

Definition at line 83 of file iterators.h.

◆ operator!=()

template<class Pred, class Base>
bool zyppng::FilterIterator< Pred, Base >::operator!= ( const FilterIterator< Pred, Base > & other) const
inline

Inequality comparison.

Definition at line 88 of file iterators.h.

◆ base()

template<class Pred, class Base>
Base const & zyppng::FilterIterator< Pred, Base >::base ( ) const
inline

Returns the underlying base iterator at its current position.

Definition at line 93 of file iterators.h.

◆ satisfy_predicate()

template<class Pred, class Base>
void zyppng::FilterIterator< Pred, Base >::satisfy_predicate ( )
inlineprivate

Advances the internal iterator until the predicate is met or _end is reached.

Definition at line 97 of file iterators.h.

Member Data Documentation

◆ _pred

template<class Pred, class Base>
Pred zyppng::FilterIterator< Pred, Base >::_pred
private

Definition at line 103 of file iterators.h.

◆ _it

template<class Pred, class Base>
Base zyppng::FilterIterator< Pred, Base >::_it
private

Definition at line 104 of file iterators.h.

◆ _end

template<class Pred, class Base>
Base zyppng::FilterIterator< Pred, Base >::_end
private

Definition at line 105 of file iterators.h.


The documentation for this class was generated from the following file: