for
loops.
More...
#include <dai/index.h>
Public Member Functions | |
multifor () | |
Default constructor. | |
multifor (const std::vector< size_t > &d) | |
Initialize from vector of index ranges. | |
operator size_t () const | |
Returns linear index (i.e., the index in the Cartesian product space). | |
size_t | operator[] (size_t k) const |
Returns k 'th index. | |
multifor & | operator++ () |
Increments the current indices (prefix). | |
void | operator++ (int) |
Increments the current indices (postfix). | |
multifor & | reset () |
Resets the state. | |
bool | valid () const |
Returns true if the current indices are valid. | |
Private Attributes | |
std::vector< size_t > | _ranges |
Stores the number of possible values of all indices. | |
std::vector< size_t > | _indices |
Stores the current values of all indices. | |
long | _linear_index |
Stores the current linear index. |
for
loops.
An example of the usage is as follows:
std::vector<size_t> ranges; ranges.push_back( 3 ); ranges.push_back( 4 ); ranges.push_back( 5 ); for( multifor s(ranges); s.valid(); ++s ) cout << "linear index: " << (size_t)s << " corresponds to indices " << s[2] << ", " << s[1] << ", " << s[0] << endl;
size_t s = 0; for( size_t s2 = 0; s2 < 5; s2++ ) for( size_t s1 = 0; s1 < 4; s1++ ) for( size_t s0 = 0; s0 < 3; s++, s0++ ) cout << "linear index: " << (size_t)s << " corresponds to indices " << s2 << ", " << s1 << ", " << s0 << endl;
dai::multifor::multifor | ( | ) | [inline] |
Default constructor.
dai::multifor::multifor | ( | const std::vector< size_t > & | d | ) | [inline] |
Initialize from vector of index ranges.
dai::multifor::operator size_t | ( | ) | const [inline] |
Returns linear index (i.e., the index in the Cartesian product space).
size_t dai::multifor::operator[] | ( | size_t | k | ) | const [inline] |
Returns k 'th index.
multifor& dai::multifor::operator++ | ( | ) | [inline] |
Increments the current indices (prefix).
void dai::multifor::operator++ | ( | int | ) | [inline] |
Increments the current indices (postfix).
multifor& dai::multifor::reset | ( | ) | [inline] |
Resets the state.
bool dai::multifor::valid | ( | ) | const [inline] |
Returns true
if the current indices are valid.
std::vector<size_t> dai::multifor::_ranges [private] |
Stores the number of possible values of all indices.
std::vector<size_t> dai::multifor::_indices [private] |
Stores the current values of all indices.
long dai::multifor::_linear_index [private] |
Stores the current linear index.