Template Class index_iterator#

Class Documentation#

template<class TContainer, bool bConstIterator, bool bReverseIterator>
class index_iterator#

Index based iterators used for linear array based containers.

Template Parameters:
  • TContainer – Container type to use for this iterator.

  • bConstIterator – When set, the iterator is a const iterator not allowing to change values within the container.

  • bReserseIterator – When set, the iterator starts at the end instead of at the beginning and decreases the location.

Public Types

using container_reference = std::conditional_t<bConstIterator, const TContainer&, TContainer&>#

Container type reference.

using container_pointer = std::conditional_t<bConstIterator, const TContainer*, TContainer*>#

Contaioner type pointer.

using iterator_category = std::random_access_iterator_tag#

Iterator category.

using value_type = typename TContainer::value_type#

Value type.

using difference_type = size_t#

Indexing type.

using pointer = std::conditional_t<bConstIterator, const value_type*, value_type*>#

Value type pointer.

using reference = std::conditional_t<bConstIterator, const value_type&, value_type&>#

Value type reference.

Public Functions

inline index_iterator()#

Default constructor.

inline index_iterator(container_pointer pContainer)#

Iterator initialization.

Parameters:

pContainer[in] Pointer to the container.

inline index_iterator(const index_iterator &rit)#

Copy constructor.

Parameters:

rit[in] Reference to the iterator to copy from.

inline index_iterator(const index_iterator<TContainer, !bConstIterator, bReverseIterator> &rit)#

Copy constructor.

Parameters:

rit[in] Reference to the iterator to copy from.

inline index_iterator(index_iterator &&rit) noexcept#

Move constructor.

Parameters:

rit[in] Reference to the iterator to move from.

inline index_iterator &operator=(const index_iterator &rit)#

Assignment operator.

Parameters:

rit[in] Reference to the iterator to copy from.

Returns:

Returns a reference to the iterator.

inline index_iterator &operator=(const index_iterator<TContainer, !bConstIterator, bReverseIterator> &rit)#

Assignment operator.

Parameters:

rit[in] Reference to the iterator to copy from.

Returns:

Returns a reference to the iterator.

inline index_iterator &operator=(index_iterator &&rit) noexcept#

Move operator.

Parameters:

rit[in] Reference to the iterator to move from.

Returns:

Returns a reference to the iterator.

inline bool is_valid(container_reference rContainer) const#

Does the iterator iterate the same container.

Parameters:

rContainer[in] Reference to the container to check whether the iterators are iterating the same container.

Returns:

Returns ‘true’ when the iterator iterates the same container; otherwise returns ‘false’.

inline bool operator==(const index_iterator &rit) const#

Compare two iterators for iterating the same container and pointing to the same position.

Parameters:

rit[in] Reference to the iterator to use for the comparison.

Returns:

Returns ‘true’ when the iterators point to the same container and have the same position.

inline bool operator==(const index_iterator<TContainer, !bConstIterator, bReverseIterator> &rit) const#

Compare two iterators for iterating the same container and pointing to the same position.

Parameters:

rit[in] Reference to the iterator to use for the comparison.

Returns:

Returns ‘true’ when the iterators point to the same container and have the same position.

inline bool operator!=(const index_iterator &rit) const#

Compare two iterators for iterating the different containers or pointing to the another position.

Parameters:

rit[in] Reference to the iterator to use for the comparison.

Returns:

Returns ‘true’ when the iterators point to different containers or have different positions.

inline bool operator!=(const index_iterator<TContainer, !bConstIterator, bReverseIterator> &rit) const#

Compare two iterators for iterating the different containers or pointing to the another position.

Parameters:

rit[in] Reference to the iterator to use for the comparison.

Returns:

Returns ‘true’ when the iterators point to different containers or have different positions.

inline reference operator*() const#

Get the value from the container at the location the iterator is pointing to.

Returns:

Reference to the value.

inline pointer operator->() const#

Pointer operation the value from the container at the location the iterator is pointing to.

Remark

Only valid for container storing pointers.

Returns:

Reference to the value.

inline index_iterator &operator++()#

Increase the iterator with one position. Doesn’t go past the one position behind the back.

Returns:

Reference to the iterator.

inline index_iterator operator++(int)#

Copy the current iterator and increase the copied iterator with one position. Doesn’t go past the one position behind the back.

Returns:

Copied and increased iterator.

inline index_iterator &operator--() noexcept#

Decrease the iterator with one position. Doesn’t go before the front position.

Returns:

Reference to the iterator.

inline index_iterator operator--(int) noexcept#

Copy the current iterator and decrease the copied iterator with one position. Doesn’t go before the front position.

Returns:

Copied and decreased iterator.

inline index_iterator &operator+=(size_t nOffset) noexcept#

Increase the iterator with nOsset positions. Doesn’t go past the one position behind the back.

Parameters:

nOffset[in] The amount of positions to increase.

Returns:

Reference to the iterator.

inline index_iterator operator+(size_t nOffset) const noexcept#

Copy the current iterator and increase the copied iterator with nOffset positions. Doesn’t go past the one position behind the back.

Parameters:

nOffset[in] The amount of positions to increase.

Returns:

Copied and increased iterator.

inline index_iterator &operator-=(size_t nOffset) noexcept#

Decrease the iterator with nOffset positions. Doesn’t go before the front position.

Parameters:

nOffset[in] The amount of positions to decrease.

Returns:

Reference to the iterator.

inline index_iterator operator-(size_t nOffset) const noexcept#

Copy the current iterator and decrease the copied iterator with nOffset positions. Doesn’t go before the front position.

Parameters:

nOffset[in] The amount of positions to increase.

Returns:

Copied and decreased iterator.

inline difference_type operator-(index_iterator it) const#

Subtract the indices of two iterators of the same type.

Parameters:

it[in] The iterator to use for subtraction.

Returns:

The difference between the contained index and the index of the supplied iterator.

inline reference operator[](size_t nOffset) const#

Get the value from the container at the location the iterator is pointing to added with an offset.

Parameters:

nOffset[in] The offset to increase the location.

Returns:

Reference to the value at the location increased with an offset.