BaseIterator< COLLECTION, STRIDED > Class Template Reference

#include <block.h>

Detailed Description

template<typename COLLECTION, Bool STRIDED>
class maxon::BaseIterator< COLLECTION, STRIDED >

The BaseIterator internally is a pointer. So using it to iterate over an array or parts of it is as efficient as using a real pointer (for more ease of use you may want to invoke this via the C++11 range based for loop).

As already said you can use an Iterator almost like a pointer, e.g.

it++; // go to the next element
it--; // go to the previous element
it += 5; // advance by 5 elements
it -= 3; // go back 3 elements
cnt = itB - itA; // number of elements from itA to itB
it = array.Begin(); // iterator to the first element of the array
*it = value; // assign value to the elements referenced by the iterator
value = *it; // get value of the element referenced by the iterator
PyObject * value
Definition: abstract.h:715

Please note that using a postfix operator access (*it++ or *it–) can be slower than using the prefix form or a separate assignment. E.g.

value = *it++;

is most likely slower than

value = it; ++it;

or

value = it; it++;

because *it++ requires a temporary copy of the iterator that the compiler may not be able to remove during optimization. As long as you only use the iterator's postfix operator without assignment it should be fine because the compiler will remove the temporary copy.

You can either type alias the BaseIterator (like the BaseArray does) or inherit from it.

Template Parameters
COLLECTIONType of the array.
STRIDEDFalse for pointer-only iterator. True if the iterator has to support a variable stride offset (slower and requires another member variable).

Classes

class  ResultFunctions
 

Public Types

using CollectionType = COLLECTION
 
using ValueType = typename InheritConst< typename COLLECTION::ValueType, COLLECTION >::type
 
using iterator_category = std::random_access_iterator_tag
 
using difference_type = Int
 
using value_type = ValueType
 
using pointer = ValueType *
 
using reference = ValueType &
 

Public Member Functions

 BaseIterator (CollectionType &a, Int start=0)
 
 BaseIterator (ValueType *pos=nullptr, Int index=0, Int stride=0)
 
 BaseIterator (const BaseIterator &src)=default
 
BaseIteratoroperator= (const BaseIterator &src)=default
 
 operator BaseIterator< typename std::add_const< COLLECTION >::type, STRIDED > & ()
 
 operator Bool () const
 
ValueTypeGetPtr () const
 
ValueTypeoperator* () const
 
ValueTypeoperator-> () const
 
Bool operator== (const BaseIterator &b) const
 
Bool operator< (const BaseIterator &b) const
 
 MAXON_OPERATOR_COMPARISON (BaseIterator)
 
BaseIteratoroperator++ ()
 
BaseIterator operator++ (int)
 
BaseIteratoroperator+= (Int i)
 
BaseIteratoroperator-- ()
 
BaseIterator operator-- (int)
 
BaseIteratoroperator-= (Int i)
 
BaseIterator operator+ (Int i) const
 
BaseIterator operator- (Int i) const
 
Int operator- (const BaseIterator &b) const
 

Static Public Attributes

static const Bool isLinearIterator
 

Protected Attributes

ValueType_data
 

Member Typedef Documentation

◆ CollectionType

using CollectionType = COLLECTION

◆ ValueType

using ValueType = typename InheritConst<typename COLLECTION::ValueType, COLLECTION>::type

◆ iterator_category

using iterator_category = std::random_access_iterator_tag

◆ difference_type

◆ value_type

◆ pointer

using pointer = ValueType*

◆ reference

using reference = ValueType&

Constructor & Destructor Documentation

◆ BaseIterator() [1/3]

BaseIterator ( CollectionType a,
Int  start = 0 
)
explicit

◆ BaseIterator() [2/3]

BaseIterator ( ValueType pos = nullptr,
Int  index = 0,
Int  stride = 0 
)
explicit

◆ BaseIterator() [3/3]

BaseIterator ( const BaseIterator< COLLECTION, STRIDED > &  src)
default

Member Function Documentation

◆ operator=()

BaseIterator& operator= ( const BaseIterator< COLLECTION, STRIDED > &  src)
default

◆ operator BaseIterator< typename std::add_const< COLLECTION >::type, STRIDED > &()

operator BaseIterator< typename std::add_const< COLLECTION >::type, STRIDED > & ( )

◆ operator Bool()

operator Bool ( ) const
explicit
Returns
true if the iterator points to an element.

◆ GetPtr()

ValueType* GetPtr ( ) const

◆ operator*()

ValueType& operator* ( ) const

◆ operator->()

ValueType* operator-> ( ) const

◆ operator==()

Bool operator== ( const BaseIterator< COLLECTION, STRIDED > &  b) const

◆ operator<()

Bool operator< ( const BaseIterator< COLLECTION, STRIDED > &  b) const

◆ MAXON_OPERATOR_COMPARISON()

MAXON_OPERATOR_COMPARISON ( BaseIterator< COLLECTION, STRIDED >  )

◆ operator++() [1/2]

BaseIterator& operator++ ( )

◆ operator++() [2/2]

BaseIterator operator++ ( int  )

◆ operator+=()

BaseIterator& operator+= ( Int  i)

◆ operator--() [1/2]

BaseIterator& operator-- ( )

◆ operator--() [2/2]

BaseIterator operator-- ( int  )

◆ operator-=()

BaseIterator& operator-= ( Int  i)

◆ operator+()

BaseIterator operator+ ( Int  i) const

◆ operator-() [1/2]

BaseIterator operator- ( Int  i) const

◆ operator-() [2/2]

Int operator- ( const BaseIterator< COLLECTION, STRIDED > &  b) const

Member Data Documentation

◆ isLinearIterator

const Bool isLinearIterator
static

◆ _data

ValueType* _data
protected