Class t8_element_array_iterator

Class Documentation

class t8_element_array_iterator

This class resembles a Random-Access-Iterator wrapper for the content of a t8_element_array_t.

The iterator can be dereferenced in order to receive a t8_element_t pointer to the corresponding index. These iterators may be used in algorithms of the standard library (e.g. std::lower_bound,…) or to iterate through a t8_element_array_t. Since the actual data is serialized to char-bytes in the underlying array, we reconstruct a t8_element_t pointer and let the dereference operator return it as a value_type. Therefore, read-only operations on the t8_element_array_t are possible.

Public Types

using iterator_category = std::random_access_iterator_tag

The iterator category.

using difference_type = std::ptrdiff_t

The difference type for the iterator.

using pointer = t8_element_t**

The pointer type for the iterator.

using value_type = t8_element_t*

The value type for the iterator.

using reference = t8_element_t*&

The reference type for the iterator.

Public Functions

t8_element_array_iterator() = delete
inline t8_element_array_iterator(const t8_element_array_t *element_array, const t8_locidx_t position)

Constructor for the iterator.

Parameters:
  • element_array[in] The element array to iterate over.

  • position[in] The position in the array to start iterating from.

t8_element_array_iterator(const t8_element_array_iterator &other) = default

Copy constructor for the iterator.

Parameters:

other[in] The iterator to copy from.

t8_element_array_iterator &operator=(const t8_element_array_iterator &other) = default

Assignment operator for the iterator.

Parameters:

other[in] The iterator to assign from.

Returns:

A reference to this iterator.

t8_element_array_iterator(t8_element_array_iterator &&other) = default

Move constructor for the iterator.

Parameters:

other[in] The iterator to move from.

t8_element_array_iterator &operator=(t8_element_array_iterator &&other) = default

Move assignment operator for the iterator.

Parameters:

other[in] The iterator to move from.

Returns:

A reference to this iterator.

~t8_element_array_iterator() = default

Destructor for the iterator.

The iterator does not own the elements it points to, so no cleanup is necessary.

inline value_type operator*()

Dereference operator for the iterator.

Returns:

A pointer to the element at the current index in the array.

inline value_type operator[](const difference_type n) const

Subscript operator for the iterator.

Parameters:

n[in] The index to access.

Returns:

A pointer to the element at the given index in the array.

inline t8_element_array_iterator &operator++()

Pre-increment operator for the iterator.

Returns:

A reference to this iterator after incrementing.

inline t8_element_array_iterator operator++(int)

Post-increment operator for the iterator.

Returns:

A copy of this iterator before incrementing.

inline t8_element_array_iterator &operator--()

Pre-decrement operator for the iterator.

Returns:

A reference to this iterator after decrementing.

inline t8_element_array_iterator operator--(int)

Post-decrement operator for the iterator.

Returns:

A copy of this iterator before decrementing.

inline t8_element_array_iterator &operator+=(const difference_type n)

Add a number to the current index of the iterator.

Parameters:

n[in] The number to add.

Returns:

A reference to this iterator after adding.

inline t8_element_array_iterator &operator-=(const difference_type n)

Subtract a number from the current index of the iterator.

Parameters:

n[in] The number to subtract.

Returns:

A reference to this iterator after subtracting.

inline t8_locidx_t get_current_index() const

Return the index within the array the iterator currently points to [0,…,size].

Returns:

The index within the array the iterator currently points to.

inline t8_linearidx_t get_linear_id_at_level(const int level)

Compute the linear id at a given level for the element the iterator points to.

Parameters:

level[in] The level at which the linear id should be computed.

Returns:

The linear id at the given level.

Friends

inline friend bool operator==(const t8_element_array_iterator &iter1, const t8_element_array_iterator &iter2)

Equality operator for the iterator.

Parameters:
  • iter1[in] The first iterator to compare.

  • iter2[in] The second iterator to compare.

Returns:

True if both iterators point to the same element in the same array, false otherwise.

inline friend bool operator!=(const t8_element_array_iterator &iter1, const t8_element_array_iterator &iter2)

Inequality operator for the iterator.

Parameters:
  • iter1[in] The first iterator to compare.

  • iter2[in] The second iterator to compare.

Returns:

True if both iterators do not point to the same element in the same array, false otherwise.

inline friend bool operator<(const t8_element_array_iterator &lhs, const t8_element_array_iterator &rhs)

Comparison operators for the iterator.

These operators allow comparing two iterators based on their current index within the same array.

Parameters:
  • lhs[in] The left-hand side iterator.

  • rhs[in] The right-hand side iterator.

Returns:

True if the left-hand side iterator points to an element with a lower index than the right-hand side iterator, false otherwise.

inline friend bool operator>(const t8_element_array_iterator &lhs, const t8_element_array_iterator &rhs)

Greater-than operator for the iterator.

Parameters:
  • lhs[in] The left-hand side iterator.

  • rhs[in] The right-hand side iterator.

Returns:

True if the left-hand side iterator points to an element with a higher index than the right-hand side iterator, false otherwise.

inline friend bool operator<=(const t8_element_array_iterator &lhs, const t8_element_array_iterator &rhs)

Less-than-or-equal operator for the iterator.

Parameters:
  • lhs[in] The left-hand side iterator.

  • rhs[in] The right-hand side iterator.

Returns:

True if the left-hand side iterator points to an element with a lower or equal index than the right-hand side iterator, false otherwise.

inline friend bool operator>=(const t8_element_array_iterator &lhs, const t8_element_array_iterator &rhs)

Greater-than-or-equal operator for the iterator.

Parameters:
  • lhs[in] The left-hand side iterator.

  • rhs[in] The right-hand side iterator.

Returns:

True if the left-hand side iterator points to an element with a higher or equal index than the right-hand side iterator, false otherwise.

inline friend t8_element_array_iterator operator+(const t8_element_array_iterator &iter, const difference_type n)

Plus operator for the iterator.

Parameters:
  • iter[in] The iterator to operate on.

  • n[in] The number to add.

Returns:

A new iterator with the updated index.

inline friend t8_element_array_iterator operator+(const difference_type n, const t8_element_array_iterator &iter)

Plus operator for the iterator.

Parameters:
  • n[in] The number to add.

  • iter[in] The iterator to operate on.

Returns:

A new iterator with the updated index.

inline friend t8_element_array_iterator operator-(const t8_element_array_iterator &iter, const difference_type n)

Minus operator for the iterator.

Parameters:
  • iter[in] The iterator to operate on.

  • n[in] The number to subtract.

Returns:

A new iterator with the updated index.

inline friend difference_type operator-(const t8_element_array_iterator &lhs, const t8_element_array_iterator &rhs)

Difference operator for the iterator.

Parameters:
  • lhs[in] The left-hand side iterator.

  • rhs[in] The right-hand side iterator.

Returns:

The difference in indices between the two iterators.