libMesh
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Public Attributes | Private Member Functions | List of all members
variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType > Class Template Reference

Original Authors: Corwin Joy * Michael Gradman cjoy@.nosp@m.hous.nosp@m.ton.r.nosp@m.r.co.nosp@m.m * Micha.nosp@m.el.G.nosp@m.radma.nosp@m.n@ca.nosp@m.minus.nosp@m..com Caminus, Suite 1150, Two Allen Center, 1200 Smith Street, Houston, TX 77002 This class is an extension of variant_bidirectional_iterator to a filter_iterator similar to boost's. More...

#include <variant_filter_iterator.h>

Inheritance diagram for variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >:
[legend]

Classes

struct  Iter
 The actual iterator object is held as a template parameter here. More...
 
struct  IterBase
 Abstract base class for the iterator type. More...
 
struct  Pred
 The actual predicate is held as a template parameter here. More...
 
struct  PredBase
 Abstract base class for the predicate. More...
 

Public Types

using iterator_category = std::forward_iterator_tag
 
using value_type = Type
 
using difference_type = std::ptrdiff_t
 
using pointer = PointerType
 
using reference = ReferenceType
 
typedef variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType > Iterator
 Shortcut name for the fully-qualified typename.
 

Public Member Functions

template<typename PredType , typename IterType >
 variant_filter_iterator (const IterType &d, const IterType &e, const PredType &p)
 Templated Constructor.
 
 variant_filter_iterator ()=default
 Default Constructor.
 
 variant_filter_iterator (const Iterator &rhs)
 Copy Constructor.
 
template<class OtherType , class OtherReferenceType , class OtherPointerType , class OtherConstType , class OtherConstReferenceType , class OtherConstPointerType >
 variant_filter_iterator (const variant_filter_iterator< Predicate, OtherType, OtherReferenceType, OtherPointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &rhs)
 Copy construct from another (similar) variant_filter_iterator.
 
virtual ~variant_filter_iterator ()=default
 Destructor.
 
ReferenceType operator* () const
 unary op*() forwards on to Iter::op*()
 
PointerType operator-> () const
 op->()
 
Iteratoroperator++ ()
 op++() forwards on to Iter::op++()
 
const Iterator operator++ (int)
 postfix op++(), creates a temporary!
 
bool equal (const variant_filter_iterator &other) const
 Forwards to the equal() function defined for the IterBase pointer.
 
void swap (Iterator &lhs, Iterator &rhs)
 swap, used to implement op=
 
Iteratoroperator= (const Iterator &rhs)
 Assignment operator.
 

Public Attributes

std::unique_ptr< IterBasedata
 Ideally this private member data should have protected access.
 
std::unique_ptr< IterBaseend
 Also have a polymorphic pointer to the end object, this prevents iterating past the end.
 
std::unique_ptr< PredBasepred
 The predicate object.
 

Private Member Functions

void satisfy_predicate ()
 Advances the data pointer until it reaches the end or the predicate is satisfied.
 

Detailed Description

template<class Predicate, class Type, class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
class variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >

Original Authors: Corwin Joy * Michael Gradman cjoy@.nosp@m.hous.nosp@m.ton.r.nosp@m.r.co.nosp@m.m * Micha.nosp@m.el.G.nosp@m.radma.nosp@m.n@ca.nosp@m.minus.nosp@m..com Caminus, Suite 1150, Two Allen Center, 1200 Smith Street, Houston, TX 77002 This class is an extension of variant_bidirectional_iterator to a filter_iterator similar to boost's.

The filter iterator is modeled after a forward_iterator since to go backward and forward requires the storage of both a "begin" and "end" iterator to avoid stepping off the end or the beginning. To reduce complexity, we only allow traversal in one direction.

Author
John W. Peterson
Date
2004

Definition at line 52 of file variant_filter_iterator.h.

Member Typedef Documentation

◆ difference_type

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
using variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::difference_type = std::ptrdiff_t

Definition at line 57 of file variant_filter_iterator.h.

◆ Iterator

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
typedef variant_filter_iterator<Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType> variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::Iterator

Shortcut name for the fully-qualified typename.

Definition at line 65 of file variant_filter_iterator.h.

◆ iterator_category

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
using variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::iterator_category = std::forward_iterator_tag

Definition at line 55 of file variant_filter_iterator.h.

◆ pointer

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
using variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::pointer = PointerType

Definition at line 58 of file variant_filter_iterator.h.

◆ reference

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
using variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::reference = ReferenceType

Definition at line 59 of file variant_filter_iterator.h.

◆ value_type

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
using variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::value_type = Type

Definition at line 56 of file variant_filter_iterator.h.

Constructor & Destructor Documentation

◆ variant_filter_iterator() [1/4]

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
template<typename PredType , typename IterType >
variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::variant_filter_iterator ( const IterType &  d,
const IterType &  e,
const PredType &  p 
)
inline

Templated Constructor.

Allows you to construct the iterator and predicate from any types. Also advances the data pointer to the first entry which satisfies the predicate.

Note
The initialization list uses the default IterBase copy constructor.

Definition at line 325 of file variant_filter_iterator.h.

327 :
328 data ( std::make_unique<Iter<IterType>>(d) ),
329 end ( std::make_unique<Iter<IterType>>(e) ),
330 pred ( std::make_unique<Pred<IterType,PredType>>(p) )
331 {
332 this->satisfy_predicate();
333 }
std::unique_ptr< IterBase > end
Also have a polymorphic pointer to the end object, this prevents iterating past the end.
void satisfy_predicate()
Advances the data pointer until it reaches the end or the predicate is satisfied.
std::unique_ptr< PredBase > pred
The predicate object.
std::unique_ptr< IterBase > data
Ideally this private member data should have protected access.

References variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::satisfy_predicate().

◆ variant_filter_iterator() [2/4]

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::variant_filter_iterator ( )
default

Default Constructor.

◆ variant_filter_iterator() [3/4]

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::variant_filter_iterator ( const Iterator rhs)
inline

Copy Constructor.

Copy the internal data instead of sharing it.

Definition at line 344 of file variant_filter_iterator.h.

344 :
345 data (rhs.data ? rhs.data->clone() : nullptr),
346 end (rhs.end ? rhs.end->clone() : nullptr),
347 pred (rhs.pred ? rhs.pred->clone() : nullptr) {}

◆ variant_filter_iterator() [4/4]

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
template<class OtherType , class OtherReferenceType , class OtherPointerType , class OtherConstType , class OtherConstReferenceType , class OtherConstPointerType >
variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::variant_filter_iterator ( const variant_filter_iterator< Predicate, OtherType, OtherReferenceType, OtherPointerType, OtherConstType, OtherConstReferenceType, OtherConstPointerType > &  rhs)
inline

Copy construct from another (similar) variant_filter_iterator.

The Predicate is the same, but the Type, ReferenceType and PointerType are different. Example: You are iterating over a std::vector<int *> with std::vector<int *>::iterator Then, you have: Type=int * , ReferenceType=int *& , PointerType=int ** On the other hand, when you iterate using std::vector<int *>::const_iterator you have: Type=int * const, ReferenceType=int * const & , PointerType=int * const *

Definition at line 362 of file variant_filter_iterator.h.

364 : data (rhs.data ? rhs.data->const_clone() : nullptr),
365 end (rhs.end ? rhs.end->const_clone() : nullptr),
366 pred (rhs.pred ? rhs.pred->const_clone() : nullptr)
367 {
368 }

◆ ~variant_filter_iterator()

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
virtual variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::~variant_filter_iterator ( )
virtualdefault

Destructor.

Member Function Documentation

◆ equal()

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
bool variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::equal ( const variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType > &  other) const
inline

Forwards to the equal() function defined for the IterBase pointer.

Definition at line 416 of file variant_filter_iterator.h.

417 {
418 return data->equal(other.data);
419 }

References variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::data.

◆ operator*()

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
ReferenceType variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::operator* ( ) const
inline

unary op*() forwards on to Iter::op*()

Definition at line 378 of file variant_filter_iterator.h.

379 {
380 return **data;
381 }

References variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::data.

◆ operator++() [1/2]

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
Iterator & variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::operator++ ( )
inline

◆ operator++() [2/2]

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
const Iterator variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::operator++ ( int  )
inline

postfix op++(), creates a temporary!

Definition at line 404 of file variant_filter_iterator.h.

405 {
406 Iterator oldValue(*this); // standard is to return old value
407 ++*data;
408 this->satisfy_predicate();
409 return oldValue;
410 }
variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType > Iterator
Shortcut name for the fully-qualified typename.

References variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::data, and variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::satisfy_predicate().

◆ operator->()

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
PointerType variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::operator-> ( ) const
inline

op->()

Definition at line 386 of file variant_filter_iterator.h.

387 {
388 return &**this;
389 }

◆ operator=()

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
Iterator & variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::operator= ( const Iterator rhs)
inline

Assignment operator.

Definition at line 439 of file variant_filter_iterator.h.

440 {
441 Iterator temp(rhs);
442 swap(temp, *this);
443 return *this;
444 }
void swap(Iterator &lhs, Iterator &rhs)
swap, used to implement op=

References variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::swap().

◆ satisfy_predicate()

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
void variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::satisfy_predicate ( )
inlineprivate

◆ swap()

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
void variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::swap ( Iterator lhs,
Iterator rhs 
)
inline

Member Data Documentation

◆ data

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
std::unique_ptr<IterBase> variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::data

◆ end

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
std::unique_ptr<IterBase> variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::end

◆ pred

template<class Predicate , class Type , class ReferenceType = Type &, class PointerType = Type *, class ConstType = const Type, class ConstReferenceType = const Type &, class ConstPointerType = const Type *>
std::unique_ptr<PredBase> variant_filter_iterator< Predicate, Type, ReferenceType, PointerType, ConstType, ConstReferenceType, ConstPointerType >::pred

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