docs/classtf_1_1IndexRange.html
class to create an index range of integral indices with a step size
| Template parameters |
|---|
| T |
This class provides functionality for managing a range of indices, where the range is defined by a starting index, an ending index, and a step size. Indices must be an integral type. For example, the range `[0, 10) with a step size 2 represents the five elements, 0, 2, 4, 6, and 8.
tf::IndexRange\<int\> range(0, 10, 2);for(auto i=range.begin(); i\<range.end(); i+=range.step\_size()) {printf("%d ", i);}
You can reset the range to a different value using tf::IndexRange::reset. This is particularly useful when the range value is only known at runtime.
tf::IndexRange\<int\> range;range.reset(0, 10, 2);for(auto i=range.begin(); i\<range.end(); i+=range.step\_size()) {printf("%d ", i);}
using index_type = T alias for the index type used in the range
IndexRange() defaultedconstructs an index range object without any initializationIndexRange(T beg, T end, T step_size) explicit constructs an IndexRange object
auto begin() const -> Tqueries the starting index of the rangeauto end() const -> Tqueries the ending index of the rangeauto step_size() const -> Tqueries the step size of the rangeauto reset(T begin, T end, T step_size) -> IndexRange<T>&updates the range with the new starting index, ending index, and step sizeauto begin(T new_begin) -> IndexRange<T>&updates the starting index of the rangeauto end(T new_end) -> IndexRange<T>&updates the ending index of the rangeauto step_size(T new_step_size) -> IndexRange<T>&updates the step size of the rangeauto size() const -> size_tqueries the number of elements in the rangeauto discrete_domain(size_t part_beg, size_t part_end) const -> IndexRangereturns a range from the given discrete domain
constructs an IndexRange object
| Parameters |
|---|
| beg |
| end |
| step_size |
queries the number of elements in the range
The number of elements is equivalent to the number of iterations in the range. For instance, the range [0, 10) with step size of 2 will iterate five elements, 0, 2, 4, 6, and 8.
tf::IndexRange\<int\> range(0, 10, 2);printf("%zu\n", range.size());// 5 (0, 2, 4, 6, 8)
returns a range from the given discrete domain
| Parameters |
|---|
| part_beg |
| part_end |
| Returns |
The discrete domain of a range refers to a counter-based sequence indexed from 0 to N, where N is the size (i.e., number of iterated elements) of the range. For example, a discrete domain of the range [0, 10) with a step size of 2 corresponds to the sequence 0, 1, 2, 3, and 4, which map to the range elements 0, 2, 4, 6, and 8.
For a partitioned domain [part_beg, part_end), this function returns the corresponding range. For instance, the partitioned domain [2, 5) for the above example returns the range [4, 10) with the same step size of 2.