template<typename T>
tf::IndexRange class

class to create an index range of integral indices with a step size

Template parameters
T the integral type of the indices

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. The indices must be of an integral type. For example, the range [0, 10) with a step size 2 represents the five elements, 0, 2, 4, 6, and 8.

Public types

using index_type = T
alias for the index type used in the range

Constructors, destructors, conversion operators

IndexRange() defaulted
constructs an index range object without any initialization
IndexRange(T beg, T end, T step_size) explicit
constructs an IndexRange object

Public functions

auto begin() const -> T
queries the starting index of the range
auto end() const -> T
queries the ending index of the range
auto step_size() const -> T
queries the step size of the range
auto reset(T begin, T end, T step_size) -> IndexRange<T>&
updates the range with the new starting index, ending index, and step size
auto begin(T new_begin) -> IndexRange<T>&
updates the starting index of the range
auto end(T new_end) -> IndexRange<T>&
updates the ending index of the range
auto step_size(T new_step_size) -> IndexRange<T>&
updates the step size of the range
auto size() const -> size_t
queries the number of elements in the range
auto discrete_domain(size_t part_beg, size_t part_end) const -> IndexRange
returns a range from the given discrete domain

Function documentation

template<typename T>
tf::IndexRange<T>::IndexRange(T beg, T end, T step_size) explicit

constructs an IndexRange object

Parameters
beg starting index of the range
end ending index of the range (exclusive)
step_size step size between consecutive indices in the range

template<typename T>
size_t tf::IndexRange<T>::size() const

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.

template<typename T>
IndexRange tf::IndexRange<T>::discrete_domain(size_t part_beg, size_t part_end) const

returns a range from the given discrete domain

Parameters
part_beg starting index of the discrete domain
part_end ending index of the discrete domain
Returns a new IndexRange object representing the given discrete domain

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.