| Taskflow: A General-purpose Task-parallel Programming System

Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
tf::IndexRange< T > Class Template Reference

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

`#include <taskflow/utility/iterator.hpp>`

## Public Types
using | index_type = T
| alias for the index type used in the range

## Public Member Functions
| IndexRange ()=default
| constructs an index range object without any initialization
| IndexRange (T beg, T end, T step_size)
| constructs an IndexRange object
T | begin () const
| queries the starting index of the range
T | end () const
| queries the ending index of the range
T | step_size () const
| queries the step size of the range
IndexRange< T > & | reset (T begin, T end, T step_size)
| updates the range with the new starting index, ending index, and step size
IndexRange< T > & | begin (T new_begin)
| updates the starting index of the range
IndexRange< T > & | end (T new_end)
| updates the ending index of the range
IndexRange< T > & | step_size (T new_step_size)
| updates the step size of the range
size_t | size () const
| queries the number of elements in the range
IndexRange | discrete_domain (size_t part_beg, size_t part_end) const
| returns a range from the given discrete domain

## Detailed Description

template<typename T>
class tf::IndexRange< T >

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. 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);
}
tf::IndexRange
class to create an index range of integral indices with a step size
Definition iterator.hpp:117

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);
}
tf::IndexRange::end
T end() const
queries the ending index of the range
Definition iterator.hpp:150
tf::IndexRange::begin
T begin() const
queries the starting index of the range
Definition iterator.hpp:145
tf::IndexRange::reset
IndexRange< T > & reset(T begin, T end, T step_size)
updates the range with the new starting index, ending index, and step size
Definition iterator.hpp:160
tf::IndexRange::step_size
T step_size() const
queries the step size of the range
Definition iterator.hpp:155

Attention
  It is user's responsibility to ensure the given range is valid. For instance, a range from 0 to 10 with a step size of -2 is invalid.

## Constructor & Destructor Documentation

## ◆ IndexRange()

template<typename T>

tf::IndexRange< T >::IndexRange | ( | T | beg,
|  | T | end,
|  | T | step_size )
| inline 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

## Member Function Documentation

## ◆ discrete_domain()

template<typename T>

IndexRange tf::IndexRange< T >::discrete_domain | ( | size_t | part_beg,
|  | size_t | part_end ) const
| inline

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.

Attention
  Users must ensure the specified domain is valid with respect to the range.

## ◆ size()

template<typename T>

size_t tf::IndexRange< T >::size | ( |  | ) | const
| inline

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)

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

- taskflow/utility/iterator.hpp