BaseList< T, NODE, HEAD, ALLOCATOR >::IteratorTemplate< CONSTITERATOR > Class Template Reference

#include <baselist.h>

Detailed Description

template<typename T, typename NODE = BaseListNode<T>, typename HEAD = BaseListHead<T, NODE>, typename ALLOCATOR = DefaultAllocator>
template<Bool CONSTITERATOR>
class maxon::BaseList< T, NODE, HEAD, ALLOCATOR >::IteratorTemplate< CONSTITERATOR >

The BaseList iterator internally is a pointer to the NODE containing the data of type T and using it to iterate over a list or parts of it is as efficient as using a real pointer to the list nodes (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 = list.Begin(); // iterator to the first element of the list
*it = value; // assign value to the elements referenced by the iterator
value = *it; // get value of the element referenced by the iterator

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;


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.

Public Types

using CollectionType = typename ConstIf< BaseList, CONSTITERATOR >::type
using Type = typename ConstIf< T, CONSTITERATOR >::type
using NodeType = typename ConstIf< NODE, CONSTITERATOR >::type

Public Member Functions

 IteratorTemplate (CollectionType &l)
 IteratorTemplate (NodeType *pos=nullptr)
 IteratorTemplate (const IteratorTemplate &src)
IteratorTemplateoperator= (const IteratorTemplate &src)
 operator ConstIterator & ()
TypeGetPtr () const
 operator Bool () const
Typeoperator* () const
Typeoperator-> () const
Bool operator== (const IteratorTemplate &b) const
Bool operator!= (const IteratorTemplate &b) const
IteratorTemplateoperator++ ()
const IteratorTemplate operator++ (int)
IteratorTemplateoperator-- ()
const IteratorTemplate operator-- (int)
IteratorTemplateoperator+= (Int i)
IteratorTemplate operator+ (Int i) const
IteratorTemplateoperator-= (Int i)
IteratorTemplate operator- (Int i) const
Int operator- (const IteratorTemplate &b) const
NodeTypeGetNode () const

Static Public Attributes

static const Bool isLinearIterator

Private Attributes


Member Typedef Documentation

◆ CollectionType

using CollectionType = typename ConstIf<BaseList, CONSTITERATOR>::type

◆ Type

using Type = typename ConstIf<T, CONSTITERATOR>::type

◆ NodeType

using NodeType = typename ConstIf<NODE, CONSTITERATOR>::type

Constructor & Destructor Documentation

◆ IteratorTemplate() [1/3]

IteratorTemplate ( CollectionType l)

◆ IteratorTemplate() [2/3]

IteratorTemplate ( NodeType pos = nullptr)

◆ IteratorTemplate() [3/3]

IteratorTemplate ( const IteratorTemplate< CONSTITERATOR > &  src)

Member Function Documentation

◆ operator=()

IteratorTemplate& operator= ( const IteratorTemplate< CONSTITERATOR > &  src)

◆ operator ConstIterator &()

operator ConstIterator & ( )

◆ GetPtr()

Type* GetPtr ( ) const

◆ operator Bool()

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

◆ operator*()

Type& operator* ( ) const

◆ operator->()

Type* operator-> ( ) const

◆ operator==()

Bool operator== ( const IteratorTemplate< CONSTITERATOR > &  b) const

◆ operator!=()

Bool operator!= ( const IteratorTemplate< CONSTITERATOR > &  b) const

◆ operator++() [1/2]

IteratorTemplate& operator++ ( )

◆ operator++() [2/2]

const IteratorTemplate operator++ ( int  )

◆ operator--() [1/2]

IteratorTemplate& operator-- ( )

◆ operator--() [2/2]

const IteratorTemplate operator-- ( int  )

◆ operator+=()

IteratorTemplate& operator+= ( Int  i)

◆ operator+()

IteratorTemplate operator+ ( Int  i) const

◆ operator-=()

IteratorTemplate& operator-= ( Int  i)

◆ operator-() [1/2]

IteratorTemplate operator- ( Int  i) const

◆ operator-() [2/2]

Int operator- ( const IteratorTemplate< CONSTITERATOR > &  b) const

◆ GetNode()

NodeType* GetNode ( ) const

Member Data Documentation

◆ isLinearIterator

const Bool isLinearIterator

◆ _node

NodeType* _node