lucid  0.0.1
Lifting-based Uncertain Control Invariant Dynamics
Loading...
Searching...
No Matches
lucid::IndexIterator< T > Class Template Reference

Iterator over all possible indexes in a given range. More...

#include <IndexIterator.h>

Public Member Functions

 IndexIterator (T max_value)
 Construct an index iterator with size given by max_value.size().
 
 IndexIterator (T min_value, T max_value)
 Construct an index iterator with size given by max_value.size().
 
 IndexIterator (std::size_t size, T max_value)
 Construct an index iterator with the given size.
 
 IndexIterator (std::size_t size, T min_value, T max_value)
 Construct an index iterator with the given size.
 
IndexIteratorreset ()
 Reset the iterator to the initial state.
 
IndexIteratoroperator++ ()
 Increment the iterator.
 
const std::vector< Index > & indexes () const
 Get read-only access to the whole vector of indexes of the index iterator.
 
Index operator[] (const std::size_t index) const
 Get read-only access to the index element of the index iterator.
 
 operator bool () const
 Check whether the index iterator is done iterating, having gone over all valid indexes.
 

Static Public Member Functions

static IndexIterator< T > end ()
 Create an exhausted index iterator by assigning the same value to both min and max: 0.
 

Private Attributes

min_value_
 Minimum value for each index. Inclusive.
 
max_value_
 Maximum value for each index. Exclusive.
 
std::vector< Index > indexes_
 Current indexes.
 

Detailed Description

template<IsAnyOf< Index, std::vector< Index > > T>
class lucid::IndexIterator< T >

Iterator over all possible indexes in a given range.

It also supports individual range for each index.

for (IndexIterator<Index> it{3, 0, 2}; it; ++it) {
std::cout << it[0] << it[1] << it[2] << std::endl;
}
for (IndexIterator<std::vector<Index>> it{{0, -1, 0}, {4, 2, 2}}; it; ++it) {
std::cout << it[0] << it[1] << it[2] << std::endl;
}
IndexIterator(T max_value)
Construct an index iterator with size given by max_value.size().
Definition IndexIterator.cpp:42
Template Parameters
Ttype of the range. It can be a single value or a vector of values.

Constructor & Destructor Documentation

◆ IndexIterator() [1/4]

template<IsAnyOf< Index, std::vector< Index > > T>
requires std::is_same_v<T, std::vector<Index>>
lucid::IndexIterator< T >::IndexIterator ( T max_value)
explicit

Construct an index iterator with size given by max_value.size().

Each of the indexes will go from [0 to max_value[i] - 1] (inclusive).

Parameters
max_valuemaximum value for each index

◆ IndexIterator() [2/4]

template<IsAnyOf< Index, std::vector< Index > > T>
requires std::is_same_v<T, std::vector<Index>>
lucid::IndexIterator< T >::IndexIterator ( T min_value,
T max_value )

Construct an index iterator with size given by max_value.size().

Each of the indexes will go from [min_value[i] to max_value[i] - 1] (inclusive).

Parameters
min_valueminimum value for each index
max_valuemaximum value for each index

◆ IndexIterator() [3/4]

template<IsAnyOf< Index, std::vector< Index > > T>
requires std::is_same_v<T, Index>
lucid::IndexIterator< T >::IndexIterator ( std::size_t size,
T max_value )

Construct an index iterator with the given size.

Each of the indexes will go from [0 to max_value - 1] (inclusive).

Parameters
sizenumber of indexes
max_valuemaximum value for each index

◆ IndexIterator() [4/4]

template<IsAnyOf< Index, std::vector< Index > > T>
requires std::is_same_v<T, Index>
lucid::IndexIterator< T >::IndexIterator ( std::size_t size,
T min_value,
T max_value )

Construct an index iterator with the given size.

Each of the indexes will go from [min_value to max_value - 1] (inclusive).

Parameters
sizenumber of indexes
min_valueminimum value for each index
max_valuemaximum value for each index

Member Function Documentation

◆ end()

template<IsAnyOf< Index, std::vector< Index > > T>
IndexIterator< T > lucid::IndexIterator< T >::end ( )
static

Create an exhausted index iterator by assigning the same value to both min and max: 0.

Useful to create something cheap to indicate that there is nothing to iterate.

Returns
index iterator already exhausted

◆ indexes()

template<IsAnyOf< Index, std::vector< Index > > T>
const std::vector< Index > & lucid::IndexIterator< T >::indexes ( ) const
inlinenodiscard

Get read-only access to the whole vector of indexes of the index iterator.

Returns
whole vector of indexes of the index iterator

◆ operator bool()

template<IsAnyOf< Index, std::vector< Index > > T>
lucid::IndexIterator< T >::operator bool ( ) const

Check whether the index iterator is done iterating, having gone over all valid indexes.

Returns
true if the index iterator is done iterating, having gone over all valid indexes
false if the index iterator is not done iterating, having gone over all valid indexes

◆ operator++()

template<IsAnyOf< Index, std::vector< Index > > T>
IndexIterator< T > & lucid::IndexIterator< T >::operator++ ( )

Increment the iterator.

Go to the next index.

Returns
reference to the iterator

◆ operator[]()

template<IsAnyOf< Index, std::vector< Index > > T>
Index lucid::IndexIterator< T >::operator[] ( const std::size_t index) const
inlinenodiscard

Get read-only access to the index element of the index iterator.

Returns
index element of the index iterator

◆ reset()

template<IsAnyOf< Index, std::vector< Index > > T>
IndexIterator< T > & lucid::IndexIterator< T >::reset ( )

Reset the iterator to the initial state.

Returns
reference to the iterator

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