BaseIterator< COLLECTION, STRIDED > Class Template Reference Data Structures

#include <block.h>

详细描述

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

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
COLLECTION Type of the array.
STRIDED False 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 &

公共成员函数

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

静态公共属性

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

using difference_type = Int

◆  value_type

using value_type = ValueType

◆  pointer

using pointer = ValueType *

◆  reference

using reference = ValueType &

构造函数 & 析构函数文档编制

◆  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

成员函数文档编制

◆  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
返回
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
maxon::NonConstArray::Begin
ConstIterator Begin() const
定义: array.h:922