PLaSK library
Loading...
Searching...
No Matches
plask::IndexedIterator< ContainerType, Reference, dereference_f > Struct Template Reference

Template to create iterators for containers which have operator[]. More...

#include <plask/utils/iterators.hpp>

Inheritance diagram for plask::IndexedIterator< ContainerType, Reference, dereference_f >:
[legend]
Collaboration diagram for plask::IndexedIterator< ContainerType, Reference, dereference_f >:
[legend]

Public Member Functions

 IndexedIterator ()
 Construct uninitialized iterator. Don't use it before initialization.
 
 IndexedIterator (ContainerType *container, std::size_t index)
 Construct iterator which point to given index in given container.
 
std::size_t getIndex () const
 Get current iterator position (index).
 

Public Attributes

ContainerTypecontainer
 Pointer to container over which we iterate.
 
std::size_t index
 Current iterator position (index).
 

Friends

class boost::iterator_core_access
 

Detailed Description

template<typename ContainerType, typename Reference = decltype(std::declval<ContainerType>()[0]), Reference(*)(ContainerType &container, std::size_t index) dereference_f = dereferenceByIndexOperator<ContainerType, Reference>>
struct plask::IndexedIterator< ContainerType, Reference, dereference_f >

Template to create iterators for containers which have operator[].

Template Parameters
ContainerTypetype of container (can be const or non-const)
Referenceiterator reference type, should be the same type which return container operator[] In most cases it can be auto-deduced from ContainerType, but only if ContainerType is fully defined and known.
dereference_ffunction which perform dereference on container, by default calls operator[]

Example:

//Typdefes for iterator types:
//(note that second template parameter can't be auto-deduced because MyIntContainer is not fully defined yet)
//begin() and end() methods (non-const and const versions):
iterator begin() { return iterator(0); } //0 is begin index
const_iterator begin() const { return const_iterator(0); } //0 is begin index
iterator end() { return iterator(size()); } //size() is end index
const_iterator end() const { return const_iterator(size()); } //size() is end index
//Methods to get object by index, etc.:
int& operator[](std::size_t index) { //used by iterator
//code which returns object with given index
}
const int& operator[](std::size_t index) const { //used by const_iterator
//code which returns object with given index
}
std::size_t size() const { //used by end()
//code which returns number of objects
}
};

Definition at line 260 of file iterators.hpp.

Constructor & Destructor Documentation

◆ IndexedIterator() [1/2]

template<typename ContainerType , typename Reference = decltype(std::declval<ContainerType>()[0]), Reference(*)(ContainerType &container, std::size_t index) dereference_f = dereferenceByIndexOperator<ContainerType, Reference>>
plask::IndexedIterator< ContainerType, Reference, dereference_f >::IndexedIterator ( )
inline

Construct uninitialized iterator. Don't use it before initialization.

Definition at line 269 of file iterators.hpp.

◆ IndexedIterator() [2/2]

template<typename ContainerType , typename Reference = decltype(std::declval<ContainerType>()[0]), Reference(*)(ContainerType &container, std::size_t index) dereference_f = dereferenceByIndexOperator<ContainerType, Reference>>
plask::IndexedIterator< ContainerType, Reference, dereference_f >::IndexedIterator ( ContainerType container,
std::size_t  index 
)
inline

Construct iterator which point to given index in given container.

Parameters
containercontainer to iterate over
indexindex in container

Definition at line 276 of file iterators.hpp.

Member Function Documentation

◆ getIndex()

template<typename ContainerType , typename Reference = decltype(std::declval<ContainerType>()[0]), Reference(*)(ContainerType &container, std::size_t index) dereference_f = dereferenceByIndexOperator<ContainerType, Reference>>
std::size_t plask::IndexedIterator< ContainerType, Reference, dereference_f >::getIndex ( ) const
inline

Get current iterator position (index).

Returns
current iterator position (index)

Definition at line 282 of file iterators.hpp.

Friends And Related Symbol Documentation

◆ boost::iterator_core_access

template<typename ContainerType , typename Reference = decltype(std::declval<ContainerType>()[0]), Reference(*)(ContainerType &container, std::size_t index) dereference_f = dereferenceByIndexOperator<ContainerType, Reference>>
friend class boost::iterator_core_access
friend

Definition at line 285 of file iterators.hpp.

Member Data Documentation

◆ container

template<typename ContainerType , typename Reference = decltype(std::declval<ContainerType>()[0]), Reference(*)(ContainerType &container, std::size_t index) dereference_f = dereferenceByIndexOperator<ContainerType, Reference>>
ContainerType* plask::IndexedIterator< ContainerType, Reference, dereference_f >::container

Pointer to container over which we iterate.

Definition at line 263 of file iterators.hpp.

◆ index

template<typename ContainerType , typename Reference = decltype(std::declval<ContainerType>()[0]), Reference(*)(ContainerType &container, std::size_t index) dereference_f = dereferenceByIndexOperator<ContainerType, Reference>>
std::size_t plask::IndexedIterator< ContainerType, Reference, dereference_f >::index

Current iterator position (index).

Definition at line 266 of file iterators.hpp.


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