TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
nda::array_iterator< Rank, T, Pointer >

#include <nda/iterators.hpp>

Detailed Description

template<int Rank, typename T, typename Pointer>
class nda::array_iterator< Rank, T, Pointer >

Iterator for nda::basic_array and nda::basic_array_view types.

It is a LegacyRandomAccessIterator for 1-dimensional and a LegacyForwardIterator for multi-dimensional arrays/views.

Given the shape, strides and a pointer to the start of the data, the iterator uses an nda::detail::grid_iterator to traverse the element in the array/view.

Note
The memory layout is always assumed to be C-style. For other layouts, one has to permute the given shape and the strides according to the stride order.
Template Parameters
RankNumber of dimensions of the array.
TType of the elements in the array (can be const).
PointerType of the pointer used to access the elements in the array (might be restricted depending on the accessor).

Definition at line 215 of file iterators.hpp.

Public Types

using difference_type = std::ptrdiff_t
 Difference type.
 
using iterator_category = std::forward_iterator_tag
 Iterator category.
 
using pointer = T *
 Pointer type.
 
using reference = T &
 Reference type.
 
using value_type = T
 Value type.
 

Public Member Functions

 array_iterator ()=default
 Default constructor leaves the iterator in an uninitialized state.
 
 array_iterator (std::array< long, Rank > const &lengths, std::array< long, Rank > const &strides, T *start, bool at_end)
 Construct an iterator from the shape and the strides of an array/view, a pointer to its data and a flag indicating if the iterator is at the end.
 
auto indices ()
 Get the current position/multi-dimensional index of the iterator.
 
bool operator!= (array_iterator const &rhs) const
 Not-equal-to operator.
 
value_typeoperator* () const
 Dereference operator.
 
array_iteratoroperator++ ()
 Prefix increment operator.
 
array_iterator operator++ (int)
 Postfix increment operator.
 
value_typeoperator-> () const
 Member access operator.
 
bool operator== (array_iterator const &rhs) const
 Equal-to operator.
 

Constructor & Destructor Documentation

◆ array_iterator()

template<int Rank, typename T , typename Pointer >
nda::array_iterator< Rank, T, Pointer >::array_iterator ( std::array< long, Rank > const & lengths,
std::array< long, Rank > const & strides,
T * start,
bool at_end )
inline

Construct an iterator from the shape and the strides of an array/view, a pointer to its data and a flag indicating if the iterator is at the end.

Parameters
lengthsShape of the array/view.
stridesStrides of the array/view.
startPointer to the data.
at_endFlag indicating if the iterator is at the end.

Definition at line 256 of file iterators.hpp.

Member Function Documentation

◆ indices()

template<int Rank, typename T , typename Pointer >
auto nda::array_iterator< Rank, T, Pointer >::indices ( )
inlinenodiscard

Get the current position/multi-dimensional index of the iterator.

Returns
std::array<long, Rank> containing the current position/multi-dimensional index of the iterator.

Definition at line 263 of file iterators.hpp.

◆ operator!=()

template<int Rank, typename T , typename Pointer >
bool nda::array_iterator< Rank, T, Pointer >::operator!= ( array_iterator< Rank, T, Pointer > const & rhs) const
inlinenodiscard

Not-equal-to operator.

Parameters
rhsOther iterator to compare to.
Returns
True if the positions of the iterators are not equal, false otherwise.

Definition at line 308 of file iterators.hpp.

◆ operator*()

template<int Rank, typename T , typename Pointer >
value_type & nda::array_iterator< Rank, T, Pointer >::operator* ( ) const
inlinenodiscard

Dereference operator.

Returns
Reference to the element at the position of the iterator.

Definition at line 269 of file iterators.hpp.

◆ operator++() [1/2]

template<int Rank, typename T , typename Pointer >
array_iterator & nda::array_iterator< Rank, T, Pointer >::operator++ ( )
inline

Prefix increment operator.

Returns
Reference to the current iterator.

Definition at line 281 of file iterators.hpp.

◆ operator++() [2/2]

template<int Rank, typename T , typename Pointer >
array_iterator nda::array_iterator< Rank, T, Pointer >::operator++ ( int )
inline

Postfix increment operator.

Returns
Copy of the current iterator.

Definition at line 290 of file iterators.hpp.

◆ operator->()

template<int Rank, typename T , typename Pointer >
value_type & nda::array_iterator< Rank, T, Pointer >::operator-> ( ) const
inlinenodiscard

Member access operator.

Returns
Reference to the element at the position of the iterator.

Definition at line 275 of file iterators.hpp.

◆ operator==()

template<int Rank, typename T , typename Pointer >
bool nda::array_iterator< Rank, T, Pointer >::operator== ( array_iterator< Rank, T, Pointer > const & rhs) const
inlinenodiscard

Equal-to operator.

Parameters
rhsOther iterator to compare to.
Returns
True if the positions of the iterators are equal, false otherwise.

Definition at line 301 of file iterators.hpp.


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