Elementa v8.0.0
Minimalistic library for any C++ application (C++11 and up)
Loading...
Searching...
No Matches
Iterators extensions

Description


Diverse extensions of container iterators.

In this module you will find "multiple iterators": iterators that can iterate in a given container showing different behaviors (e.g., in a graph there are multiple ways of iterating on vertices). A multiple iterator is implemented with three classes due to the necessity of composition (there must be a base iterator class that, after copies or moves -not polymorphic- still can be differentiated in diverse iteration behaviours):

You will also find minimal Ranges (full-blown ranges are included in C++20):

Usage:

  1. Derive hidden implementations from MultItImpl, one per behavior.

    1bis.-Don't forget to add copy/move constructors and assignements to these derived classes. Call from them the corresponding methods in the base class, which take care of copying validity status.

  2. Rename if you wish MultIterator to a more comfortable name inside your container (e.g., "iterator"). Do it through "using".
  3. Derive public ranges from Range, one per iterator behavior inside your container class.
  4. Use the iterators in your application through the ranges and other methods in your containers that involve them directly.
  5. [Only if your container is a base class from which other container derive that need the same base iterator behaviors] Define in your derived containers the hidden implementations of 1, do step 2 if you wish in your base container class, do step 3 in your base class for all the behaviors, calling inside those begin() and end() methods pure virtual protected methods that you define in that base class (e.g., begin_behavior1(), end_behavior1(), ...). Then, define in the derived containers those protected methods with the proper implementation.
Author
Juan-Antonio Fernandez-Madrigal. http://jafma.net
Date
2018-2019
Collaboration diagram for Iterators extensions:

Classes

class  elementa::base::MultItImpl< Data >
 Base class for implementing diverse iteration behaviors. More...
 
class  elementa::base::MultIterator< Data, BIDIR >
 A mutable iterator that can have multiple iteration behaviors. Forward case. More...
 
class  elementa::base::MultIterator< Data, true >
 A mutable bidirectional iterator that can have multiple iteration behaviors. More...
 
class  elementa::base::Range< It >
 A range is a provider of begin() and end() iterators. More...
 
class  elementa::base::SubView< It >
 A view that refers to a segment of an existing container. More...
 
class  elementa::base::IotaView< IT >
 A view that refers to a sequence of incrementable elements, bounded or not. More...
 

Functions

template<class Data , bool BIDIR>
void elementa::base::swap (MultIterator< Data, BIDIR > &it1, MultIterator< Data, BIDIR > &it2)
 Swap function for MultIterators. More...
 

Class Documentation

◆ elementa::base::MultItImpl

class elementa::base::MultItImpl
template<class Data>
class elementa::base::MultItImpl< Data >

Base class for implementing diverse iteration behaviors.

The user must derive from this class and implement the pure virtual methods (and override operator--() if bidirectional) to build a new iteration behaviour.

Template Parameters
Datais the type of the objects that will be pointed by the iterator, and cannot be void.
Note
- The way of indicating the iterator is end() is to return nullptr in the pointedData() method.
- Implementations of iteration behaviours can be invalid. They indicate that in the inherited valid() method from Validatable.
- Any modification in the container may produce undefined effects in any iterators that use any iteration behaviour. It is recommended to get rid of existing iterators after such operations.
- This is a pattern that allows us to use a single iterator class (MultIterator) even when having multiple iteration behaviors (the ones derived from this) and the MultIterator needs to preserve its diverse identity across non-polymorphic copies and moves. This pattern is needed since several methods in the container class return or fill iterators, and that would not be possible with more than one iterator type simply derived from a base iterator.
See also
MultIterator

Definition at line 147 of file iterators.h.

Inheritance diagram for elementa::base::MultItImpl< Data >:
Collaboration diagram for elementa::base::MultItImpl< Data >:

Public Types

Types, consts., etc.
using Ptr = std::shared_ptr< MultItImpl >
 A smart pointer to the iterator implementation. More...
 

Public Member Functions

virtual std::shared_ptr< MultItImpl< Data > > clone (void) const=0
 Derived classes must implement this method, returning the same return.
 
virtual std::shared_ptr< MultItImpl< Data > > * emptyClone (void) const
 Derived classes can override this to provide a clone that is "empty". More...
 
Constructors
 MultItImpl (void)
 Default constructor: invalid state. More...
 
 MultItImpl (const MultItImpl &oth)
 Copy constructor. More...
 
MultItImploperator= (const MultItImpl &oth)
 Copy assignment. More...
 
 MultItImpl (MultItImpl &&oth)
 Move constructor. More...
 
MultItImploperator= (MultItImpl &&oth)
 Move assignment. More...
 
virtual ~MultItImpl (void)=default
 Virtual destructor.
 
Interface methods
virtual Data & operator* (void)=0
 Must return a ref to the pointed data, or throw in invalid state. More...
 
virtual Data * pointedData (void) const =0
 Must return a pointer to the data under the iterator. More...
 
virtual MultItImploperator++ (void)=0
 Prefix increment. More...
 
virtual bool isEnd (void) const
 Detect whether it is end iterator. More...
 
Other methods
void invalidate (void)
 Invalidate the iterator. More...
 
virtual MultItImploperator-- (void)
 Prefix decrement, for possible bidirectional iterations. More...
 
virtual bool operator== (const MultItImpl &oth) const
 Equality between iterators. By default, equality of the pointed data. More...
 
virtual bool operator!= (const MultItImpl &oth) const
 Unequality between iterators. More...
 
virtual std::string to_string (void) const
 Return a string with info about the iterator implementation. More...
 

Member Typedef Documentation

◆ Ptr

template<class Data >
using elementa::base::MultItImpl< Data >::Ptr = std::shared_ptr<MultItImpl>

A smart pointer to the iterator implementation.

Definition at line 156 of file iterators.h.

Constructor & Destructor Documentation

◆ MultItImpl() [1/3]

template<class Data >
elementa::base::MultItImpl< Data >::MultItImpl ( void  )
inline

Default constructor: invalid state.

Definition at line 165 of file iterators.h.

◆ MultItImpl() [2/3]

template<class Data >
elementa::base::MultItImpl< Data >::MultItImpl ( const MultItImpl< Data > &  oth)
inline

Copy constructor.

Definition at line 168 of file iterators.h.

References ELE_CODE_TRACE_OFF.

◆ MultItImpl() [3/3]

template<class Data >
elementa::base::MultItImpl< Data >::MultItImpl ( MultItImpl< Data > &&  oth)
inline

Move constructor.

Definition at line 178 of file iterators.h.

References ELE_CODE_TRACE_OFF.

Member Function Documentation

◆ operator=() [1/2]

template<class Data >
MultItImpl & elementa::base::MultItImpl< Data >::operator= ( const MultItImpl< Data > &  oth)
inline

Copy assignment.

Definition at line 172 of file iterators.h.

References ELE_CODE_TRACE_OFF.

Referenced by elementa::adts::graphs::Graph< Vertex, Edge >::eenteringend().

◆ operator=() [2/2]

template<class Data >
MultItImpl & elementa::base::MultItImpl< Data >::operator= ( MultItImpl< Data > &&  oth)
inline

Move assignment.

Definition at line 182 of file iterators.h.

References ELE_CODE_TRACE_OFF.

◆ operator*()

template<class Data >
virtual Data & elementa::base::MultItImpl< Data >::operator* ( void  )
pure virtual

Must return a ref to the pointed data, or throw in invalid state.

Exceptions
invalid_stateOn invalid state.

◆ pointedData()

template<class Data >
virtual Data * elementa::base::MultItImpl< Data >::pointedData ( void  ) const
pure virtual

Must return a pointer to the data under the iterator.

If the iterator impl. is invalid, this must throw; if it points to a non-data place (e.g., end()), must return nullptr. This method will be used for detecting equality between iterators.

Referenced by elementa::base::MultItImpl< Data >::isEnd(), elementa::base::MultItImpl< Data >::operator==(), and elementa::base::MultItImpl< Data >::to_string().

◆ operator++()

template<class Data >
virtual MultItImpl & elementa::base::MultItImpl< Data >::operator++ ( void  )
pure virtual

Prefix increment.

The only one you need to implement (postfix is in MultIterator)

◆ isEnd()

template<class Data >
virtual bool elementa::base::MultItImpl< Data >::isEnd ( void  ) const
inlinevirtual

Detect whether it is end iterator.

This can be overriden with a different implementation if the iterator does not work with pointedData.

Definition at line 213 of file iterators.h.

References elementa::base::MultItImpl< Data >::pointedData().

◆ invalidate()

template<class Data >
void elementa::base::MultItImpl< Data >::invalidate ( void  )
inline

Invalidate the iterator.

Definition at line 224 of file iterators.h.

◆ operator--()

template<class Data >
virtual MultItImpl & elementa::base::MultItImpl< Data >::operator-- ( void  )
inlinevirtual

Prefix decrement, for possible bidirectional iterations.

Definition at line 227 of file iterators.h.

References ELE_CODE_UNIMPLEMENTED.

◆ operator==()

template<class Data >
virtual bool elementa::base::MultItImpl< Data >::operator== ( const MultItImpl< Data > &  oth) const
inlinevirtual

Equality between iterators. By default, equality of the pointed data.

This can be overriden for special cases, e.g., when there is no pointed data but calculated on-the-fly one.

Definition at line 233 of file iterators.h.

References elementa::base::MultItImpl< Data >::pointedData().

◆ operator!=()

template<class Data >
virtual bool elementa::base::MultItImpl< Data >::operator!= ( const MultItImpl< Data > &  oth) const
inlinevirtual

Unequality between iterators.

See also
operator==

Definition at line 239 of file iterators.h.

◆ to_string()

template<class Data >
virtual std::string elementa::base::MultItImpl< Data >::to_string ( void  ) const
inlinevirtual

Return a string with info about the iterator implementation.

Derived classes may override this one.

Definition at line 244 of file iterators.h.

References elementa::base::kYesNoCString(), elementa::base::MultItImpl< Data >::pointedData(), elementa::base::to_number(), and elementa::patterns::Validatable::valid().

◆ emptyClone()

virtual std::shared_ptr< MultItImpl< Data > > * elementa::patterns::ClonableShared< MultItImpl< Data > >::emptyClone ( void  ) const
inlinevirtualinherited

Derived classes can override this to provide a clone that is "empty".

"Emptiness" here means that the clone is not actually a clone of the derived object, but a new object of the same class of the derived object, without no content (i.e., right after creation).

Definition at line 119 of file clonable.h.

◆ elementa::base::MultIterator

class elementa::base::MultIterator
template<class Data, bool BIDIR = false>
class elementa::base::MultIterator< Data, BIDIR >

A mutable iterator that can have multiple iteration behaviors. Forward case.

This is the iterator that the final user will receive and use. Each iteration behavior is implemented with MultItImpl.

Template Parameters
Datais the type of the objects pointed by the iterator, and cannot be void.
Note
- Find the different iterator categories in STL here: https://en.cppreference.com/w/cpp/iterator/iterator_tags
- ForwardLegacyIterators require:
  • Move constructible
  • Copy constructible
  • Move assignable
  • Copy assignable
  • Destructible
  • Swappable
  • Equality comparable (== and != based on the fact that both iterators are valid, pointing into the same container, and the referenced elements are or not the same)
  • Pre- and post-incrementable (++it, it++)
  • Multipass guarantee (see https://en.cppreference.com/w/cpp/iterator/iterator_tags)
- BidirectionalLegacyIterators require, in addition, operator--().
See also
MultItImpl

Definition at line 298 of file iterators.h.

Public Types

Types, consts, etc.
using Category = std::forward_iterator_tag
 Category of the iterator (for STL-compatibility) More...
 
using T = Data
 Iterated data (for STL-compatibility) More...
 
using Distance = std::ptrdiff_t
 Distance between iterators (for STL-compatibility) More...
 
using Pointer = T *
 Pointer to data (for STL-compatibility) More...
 
using Reference = T &
 Reference to data (for STL-compatibility) More...
 
using ImplementationPtr = typename MultItImpl< Data >::Ptr
 Pointer to an implementation. More...
 

Public Member Functions

Constructors
 MultIterator (ImplementationPtr impl=ImplementationPtr{})
 Constructor for a given behavior. More...
 
 MultIterator (const MultIterator &oth)
 Copy constructor. Makes sure the copy is deep. More...
 
MultIteratoroperator= (const MultIterator &oth)
 Copy assignment. Makes sure the copy is deep. More...
 
 MultIterator (MultIterator &&oth)
 Move constructor. Do not move actually, just copy. More...
 
MultIteratoroperator= (MultIterator &&oth)
 Move assignment. Do not move actually, just copy. More...
 
 ~MultIterator (void)
 Destructor. More...
 
Methods
bool valid (void) const
 Return true if the iterator is in valid state. More...
 
Reference operator* (void) const
 Return a ref to the pointed data, or throw in invalid state. More...
 
MultIteratoroperator++ (void)
 Prefix increment. More...
 
MultIteratoroperator++ (int)
 Postfix increment. More...
 
bool operator== (const MultIterator &oth) const
 Check whether both are valid and point to the same data. More...
 
bool operator!= (const MultIterator &oth) const
 Inequality. More...
 
bool operator< (const MultIterator &oth) const
 Ordering (for using MultIterator in std::maps, for instance). More...
 
void swap (MultIterator &oth)
 To swap iterators is to swap their internal implementations. More...
 
bool isEnd (void) const
 Check for end. If it is invalid or points not to end, return false. More...
 
std::string to_string (void) const
 Return a string with info about the iterator. More...
 
ImplementationPtr implementation (void) const
 Consulting the implementation. More...
 

Member Typedef Documentation

◆ Category

template<class Data , bool BIDIR = false>
using elementa::base::MultIterator< Data, BIDIR >::Category = std::forward_iterator_tag

Category of the iterator (for STL-compatibility)

Definition at line 306 of file iterators.h.

◆ T

template<class Data , bool BIDIR = false>
using elementa::base::MultIterator< Data, BIDIR >::T = Data

Iterated data (for STL-compatibility)

Definition at line 309 of file iterators.h.

◆ Distance

template<class Data , bool BIDIR = false>
using elementa::base::MultIterator< Data, BIDIR >::Distance = std::ptrdiff_t

Distance between iterators (for STL-compatibility)

Definition at line 312 of file iterators.h.

◆ Pointer

template<class Data , bool BIDIR = false>
using elementa::base::MultIterator< Data, BIDIR >::Pointer = T*

Pointer to data (for STL-compatibility)

Definition at line 315 of file iterators.h.

◆ Reference

template<class Data , bool BIDIR = false>
using elementa::base::MultIterator< Data, BIDIR >::Reference = T&

Reference to data (for STL-compatibility)

Definition at line 318 of file iterators.h.

◆ ImplementationPtr

template<class Data , bool BIDIR = false>
using elementa::base::MultIterator< Data, BIDIR >::ImplementationPtr = typename MultItImpl<Data>::Ptr

Pointer to an implementation.

Definition at line 321 of file iterators.h.

Constructor & Destructor Documentation

◆ MultIterator() [1/3]

template<class Data , bool BIDIR = false>
elementa::base::MultIterator< Data, BIDIR >::MultIterator ( ImplementationPtr  impl = ImplementationPtr{})
inline

Constructor for a given behavior.

This provides the default constructor, needed for ForwardLegacyIterator and up.

Definition at line 332 of file iterators.h.

◆ MultIterator() [2/3]

template<class Data , bool BIDIR = false>
elementa::base::MultIterator< Data, BIDIR >::MultIterator ( const MultIterator< Data, BIDIR > &  oth)
inline

Copy constructor. Makes sure the copy is deep.

Definition at line 340 of file iterators.h.

References ELE_CODE_TRACE_OFF.

◆ MultIterator() [3/3]

template<class Data , bool BIDIR = false>
elementa::base::MultIterator< Data, BIDIR >::MultIterator ( MultIterator< Data, BIDIR > &&  oth)
inline

Move constructor. Do not move actually, just copy.

Definition at line 348 of file iterators.h.

References ELE_CODE_TRACE_OFF.

◆ ~MultIterator()

template<class Data , bool BIDIR = false>
elementa::base::MultIterator< Data, BIDIR >::~MultIterator ( void  )
inline

Destructor.

Definition at line 356 of file iterators.h.

Member Function Documentation

◆ operator=() [1/2]

template<class Data , bool BIDIR = false>
MultIterator & elementa::base::MultIterator< Data, BIDIR >::operator= ( const MultIterator< Data, BIDIR > &  oth)
inline

Copy assignment. Makes sure the copy is deep.

Definition at line 344 of file iterators.h.

References ELE_CODE_TRACE_OFF.

◆ operator=() [2/2]

template<class Data , bool BIDIR = false>
MultIterator & elementa::base::MultIterator< Data, BIDIR >::operator= ( MultIterator< Data, BIDIR > &&  oth)
inline

Move assignment. Do not move actually, just copy.

Definition at line 352 of file iterators.h.

References ELE_CODE_TRACE_OFF.

◆ valid()

◆ operator*()

template<class Data , bool BIDIR = false>
Reference elementa::base::MultIterator< Data, BIDIR >::operator* ( void  ) const
inline

Return a ref to the pointed data, or throw in invalid state.

Definition at line 368 of file iterators.h.

◆ operator++() [1/2]

template<class Data , bool BIDIR = false>
MultIterator & elementa::base::MultIterator< Data, BIDIR >::operator++ ( void  )
inline

Prefix increment.

Definition at line 371 of file iterators.h.

◆ operator++() [2/2]

template<class Data , bool BIDIR = false>
MultIterator & elementa::base::MultIterator< Data, BIDIR >::operator++ ( int  )
inline

Postfix increment.

Definition at line 375 of file iterators.h.

◆ operator==()

template<class Data , bool BIDIR = false>
bool elementa::base::MultIterator< Data, BIDIR >::operator== ( const MultIterator< Data, BIDIR > &  oth) const
inline

Check whether both are valid and point to the same data.

Definition at line 379 of file iterators.h.

◆ operator!=()

template<class Data , bool BIDIR = false>
bool elementa::base::MultIterator< Data, BIDIR >::operator!= ( const MultIterator< Data, BIDIR > &  oth) const
inline

Inequality.

Definition at line 383 of file iterators.h.

◆ operator<()

template<class Data , bool BIDIR = false>
bool elementa::base::MultIterator< Data, BIDIR >::operator< ( const MultIterator< Data, BIDIR > &  oth) const
inline

Ordering (for using MultIterator in std::maps, for instance).

Definition at line 387 of file iterators.h.

References elementa::base::MultIterator< Data, BIDIR >::valid().

◆ swap()

template<class Data , bool BIDIR = false>
void elementa::base::MultIterator< Data, BIDIR >::swap ( MultIterator< Data, BIDIR > &  oth)
inline

To swap iterators is to swap their internal implementations.

Definition at line 392 of file iterators.h.

Referenced by elementa::base::swap().

◆ isEnd()

template<class Data , bool BIDIR = false>
bool elementa::base::MultIterator< Data, BIDIR >::isEnd ( void  ) const
inline

◆ to_string()

◆ implementation()

◆ elementa::base::MultIterator< Data, true >

class elementa::base::MultIterator< Data, true >
template<class Data>
class elementa::base::MultIterator< Data, true >

A mutable bidirectional iterator that can have multiple iteration behaviors.

Bidirectional case.

Definition at line 430 of file iterators.h.

Public Types

Types, consts, etc.
using Category = std::bidirectional_iterator_tag
 Category of the iterator (for STL-compatibility) More...
 
using T = Data
 Iterated data (for STL-compatibility) More...
 
using Distance = std::ptrdiff_t
 Distance between iterators (for STL-compatibility) More...
 
using Pointer = T *
 Pointer to data (for STL-compatibility) More...
 
using Reference = T &
 Reference to data (for STL-compatibility) More...
 
using ImplementationPtr = typename MultItImpl< Data >::Ptr
 Pointer to an implementation. More...
 

Public Member Functions

Constructors
 MultIterator (ImplementationPtr impl=ImplementationPtr{})
 Constructor for a given behavior. More...
 
 MultIterator (const MultIterator &oth)
 Copy constructor. Makes sure the copy is deep. More...
 
MultIteratoroperator= (const MultIterator &oth)
 Copy assignment. Makes sure the copy is deep. More...
 
 MultIterator (MultIterator &&oth)
 Move constructor. Do not move actually, just copy. More...
 
MultIteratoroperator= (MultIterator &&oth)
 Move assignment. Do not move actually, just copy. More...
 
 ~MultIterator (void)
 Destructor. More...
 
Methods
bool valid (void) const
 Return true if the iterator is in valid state. More...
 
Reference operator* (void) const
 Return a ref to the pointed data, or throw in invalid state. More...
 
MultIteratoroperator++ (void)
 Prefix increment. More...
 
MultIteratoroperator++ (int)
 Postfix increment. More...
 
MultIteratoroperator-- (void)
 Prefix decrement. More...
 
MultIteratoroperator-- (int)
 Postfix decrement. More...
 
bool operator== (const MultIterator &oth) const
 Check whether both are valid and point to the same data. More...
 
bool operator!= (const MultIterator &oth) const
 Inequality. More...
 
bool operator< (const MultIterator &oth) const
 Ordering (for using MultIterator in std::maps, for instance). More...
 
void swap (MultIterator &oth)
 To swap iterators is to swap their internal implementations. More...
 
bool isEnd (void) const
 Check for end. If it is invalid or points not to end, return false. More...
 
std::string to_string (void) const
 Return a string with info about the iterator. More...
 
ImplementationPtr implementation (void) const
 Consulting the implementation. More...
 

Member Typedef Documentation

◆ Category

template<class Data >
using elementa::base::MultIterator< Data, true >::Category = std::bidirectional_iterator_tag

Category of the iterator (for STL-compatibility)

Definition at line 438 of file iterators.h.

◆ T

template<class Data >
using elementa::base::MultIterator< Data, true >::T = Data

Iterated data (for STL-compatibility)

Definition at line 441 of file iterators.h.

◆ Distance

template<class Data >
using elementa::base::MultIterator< Data, true >::Distance = std::ptrdiff_t

Distance between iterators (for STL-compatibility)

Definition at line 444 of file iterators.h.

◆ Pointer

template<class Data >
using elementa::base::MultIterator< Data, true >::Pointer = T*

Pointer to data (for STL-compatibility)

Definition at line 447 of file iterators.h.

◆ Reference

template<class Data >
using elementa::base::MultIterator< Data, true >::Reference = T&

Reference to data (for STL-compatibility)

Definition at line 450 of file iterators.h.

◆ ImplementationPtr

template<class Data >
using elementa::base::MultIterator< Data, true >::ImplementationPtr = typename MultItImpl<Data>::Ptr

Pointer to an implementation.

Definition at line 453 of file iterators.h.

Constructor & Destructor Documentation

◆ MultIterator() [1/3]

template<class Data >
elementa::base::MultIterator< Data, true >::MultIterator ( ImplementationPtr  impl = ImplementationPtr{})
inline

Constructor for a given behavior.

This provides the default constructor, needed for ForwardLegacyIterator and up.

Definition at line 464 of file iterators.h.

◆ MultIterator() [2/3]

template<class Data >
elementa::base::MultIterator< Data, true >::MultIterator ( const MultIterator< Data, true > &  oth)
inline

Copy constructor. Makes sure the copy is deep.

Definition at line 472 of file iterators.h.

References ELE_CODE_TRACE_OFF.

◆ MultIterator() [3/3]

template<class Data >
elementa::base::MultIterator< Data, true >::MultIterator ( MultIterator< Data, true > &&  oth)
inline

Move constructor. Do not move actually, just copy.

Definition at line 480 of file iterators.h.

References ELE_CODE_TRACE_OFF.

◆ ~MultIterator()

template<class Data >
elementa::base::MultIterator< Data, true >::~MultIterator ( void  )
inline

Destructor.

Definition at line 488 of file iterators.h.

Member Function Documentation

◆ operator=() [1/2]

template<class Data >
MultIterator & elementa::base::MultIterator< Data, true >::operator= ( const MultIterator< Data, true > &  oth)
inline

Copy assignment. Makes sure the copy is deep.

Definition at line 476 of file iterators.h.

References ELE_CODE_TRACE_OFF.

◆ operator=() [2/2]

template<class Data >
MultIterator & elementa::base::MultIterator< Data, true >::operator= ( MultIterator< Data, true > &&  oth)
inline

Move assignment. Do not move actually, just copy.

Definition at line 484 of file iterators.h.

References ELE_CODE_TRACE_OFF.

◆ valid()

template<class Data >
bool elementa::base::MultIterator< Data, true >::valid ( void  ) const
inline

Return true if the iterator is in valid state.

Definition at line 497 of file iterators.h.

◆ operator*()

template<class Data >
Reference elementa::base::MultIterator< Data, true >::operator* ( void  ) const
inline

Return a ref to the pointed data, or throw in invalid state.

Definition at line 500 of file iterators.h.

◆ operator++() [1/2]

template<class Data >
MultIterator & elementa::base::MultIterator< Data, true >::operator++ ( void  )
inline

Prefix increment.

Definition at line 503 of file iterators.h.

◆ operator++() [2/2]

template<class Data >
MultIterator & elementa::base::MultIterator< Data, true >::operator++ ( int  )
inline

Postfix increment.

Definition at line 507 of file iterators.h.

◆ operator--() [1/2]

template<class Data >
MultIterator & elementa::base::MultIterator< Data, true >::operator-- ( void  )
inline

Prefix decrement.

Definition at line 511 of file iterators.h.

◆ operator--() [2/2]

template<class Data >
MultIterator & elementa::base::MultIterator< Data, true >::operator-- ( int  )
inline

Postfix decrement.

Definition at line 515 of file iterators.h.

◆ operator==()

template<class Data >
bool elementa::base::MultIterator< Data, true >::operator== ( const MultIterator< Data, true > &  oth) const
inline

Check whether both are valid and point to the same data.

Definition at line 519 of file iterators.h.

References elementa::base::MultIterator< Data, BIDIR >::valid().

◆ operator!=()

template<class Data >
bool elementa::base::MultIterator< Data, true >::operator!= ( const MultIterator< Data, true > &  oth) const
inline

Inequality.

Definition at line 524 of file iterators.h.

◆ operator<()

template<class Data >
bool elementa::base::MultIterator< Data, true >::operator< ( const MultIterator< Data, true > &  oth) const
inline

Ordering (for using MultIterator in std::maps, for instance).

Definition at line 528 of file iterators.h.

References elementa::base::MultIterator< Data, BIDIR >::valid().

◆ swap()

template<class Data >
void elementa::base::MultIterator< Data, true >::swap ( MultIterator< Data, true > &  oth)
inline

To swap iterators is to swap their internal implementations.

Definition at line 533 of file iterators.h.

◆ isEnd()

template<class Data >
bool elementa::base::MultIterator< Data, true >::isEnd ( void  ) const
inline

Check for end. If it is invalid or points not to end, return false.

Definition at line 537 of file iterators.h.

◆ to_string()

template<class Data >
std::string elementa::base::MultIterator< Data, true >::to_string ( void  ) const
inline

Return a string with info about the iterator.

Definition at line 541 of file iterators.h.

References elementa::base::MultIterator< Data, BIDIR >::isEnd(), and elementa::base::kYesNoCString().

◆ implementation()

template<class Data >
ImplementationPtr elementa::base::MultIterator< Data, true >::implementation ( void  ) const
inline

Consulting the implementation.

Definition at line 548 of file iterators.h.

◆ elementa::base::Range

class elementa::base::Range
template<class It>
class elementa::base::Range< It >

A range is a provider of begin() and end() iterators.

Actually, any container is a range. A range is a concept in C++20, not a class.

Template Parameters
Itis the iterator type.

Definition at line 607 of file iterators.h.

Inheritance diagram for elementa::base::Range< It >:

Public Member Functions

virtual It begin (void) const =0
 Must return an iterator pointing to the first element. More...
 
virtual It end (void) const =0
 Must return an iterator pointing past the last element. More...
 

Member Function Documentation

◆ begin()

◆ end()

◆ elementa::base::SubView

class elementa::base::SubView
template<class It>
class elementa::base::SubView< It >

A view that refers to a segment of an existing container.

A view is a concept in C++20 referring to a range that does not hold its data and evaluates its iteration lazily (and allows for composition).

Template Parameters
Itis the iterator type.

Definition at line 633 of file iterators.h.

Inheritance diagram for elementa::base::SubView< It >:
Collaboration diagram for elementa::base::SubView< It >:

Public Member Functions

 SubView (const It &itbeg, const It &itend)
 Create the view, from ITBEG to ITEND. More...
 
It begin (void) const
 Provides the begin iterator. More...
 
It end (void) const
 Provides the end iterator. More...
 

Constructor & Destructor Documentation

◆ SubView()

template<class It >
elementa::base::SubView< It >::SubView ( const It &  itbeg,
const It &  itend 
)
inline

Create the view, from ITBEG to ITEND.

Note
- This object makes copies of both iterators.
- It is the programmer's responsability to use iterators to the same container.
- The container must outlive this subrange object.

Definition at line 642 of file iterators.h.

Member Function Documentation

◆ begin()

template<class It >
It elementa::base::SubView< It >::begin ( void  ) const
inlinevirtual

Provides the begin iterator.

Implements elementa::base::Range< It >.

Definition at line 645 of file iterators.h.

◆ end()

template<class It >
It elementa::base::SubView< It >::end ( void  ) const
inlinevirtual

Provides the end iterator.

Implements elementa::base::Range< It >.

Definition at line 648 of file iterators.h.

◆ elementa::base::IotaView

class elementa::base::IotaView
template<typename IT = int>
class elementa::base::IotaView< IT >

A view that refers to a sequence of incrementable elements, bounded or not.

Its behavior is a minimalistic version of std::iota_view in C++20.

Template Parameters
ITmust be an integral type.
Note
- If the value of the integral type IT is incremented beyond its maximum possible value, and end() is considered to be reached.

Definition at line 672 of file iterators.h.

Public Member Functions

Constructors
 IotaView (IT start, IT finish) noexcept
 Bounded constructor. More...
 
 IotaView (IT start) noexcept
 Unbounded constructor. More...
 
 IotaView (void) noexcept
 Always end constructor (begin == end). More...
 
Methods
iterator_t begin (void) const noexcept
 Provides the begin iterator. More...
 
iterator_t end (void) const noexcept
 Provides the end iterator. More...
 

Constructor & Destructor Documentation

◆ IotaView() [1/3]

template<typename IT = int>
elementa::base::IotaView< IT >::IotaView ( IT  start,
IT  finish 
)
inlinenoexcept

Bounded constructor.

Definition at line 742 of file iterators.h.

◆ IotaView() [2/3]

template<typename IT = int>
elementa::base::IotaView< IT >::IotaView ( IT  start)
inlinenoexcept

Unbounded constructor.

Definition at line 748 of file iterators.h.

◆ IotaView() [3/3]

template<typename IT = int>
elementa::base::IotaView< IT >::IotaView ( void  )
inlinenoexcept

Always end constructor (begin == end).

Definition at line 754 of file iterators.h.

Member Function Documentation

◆ begin()

template<typename IT = int>
iterator_t elementa::base::IotaView< IT >::begin ( void  ) const
inlinenoexcept

Provides the begin iterator.

Definition at line 764 of file iterators.h.

References ELE_CODE_TRACE_OFF.

◆ end()

template<typename IT = int>
iterator_t elementa::base::IotaView< IT >::end ( void  ) const
inlinenoexcept

Provides the end iterator.

Definition at line 771 of file iterators.h.

References ELE_CODE_TRACE_OFF.

Function Documentation

◆ swap()

template<class Data , bool BIDIR>
void elementa::base::swap ( MultIterator< Data, BIDIR > &  it1,
MultIterator< Data, BIDIR > &  it2 
)

#include <elementa/base/iterators.h>

Swap function for MultIterators.

Definition at line 570 of file iterators.h.

References elementa::base::MultIterator< Data, BIDIR >::swap().