TRIQS/itertools 1.3.0
C++ range library
Loading...
Searching...
No Matches
Integer range

Detailed Description

An integer range is similar to a Python range.

It is defined by a start value, an end value and a step size such that the i-th value of the range is given by start + i * step.

Classes

class  itertools::range
 A lazy range of integers that mimics a Python range. More...
 
struct  itertools::range::all_t
 Denote a full range at compile-time. More...
 
struct  itertools::range::const_iterator
 Const iterator type for itertools::range. More...
 

Functions

template<typename F >
void itertools::foreach (range const &rg, F &&f)
 Apply a function to every element of an integer itertools::range.
 
template<typename... Is, typename EnableIf = std::enable_if_t<(std::is_integral_v<Is> and ...), int>>
auto itertools::product_range (Is... is)
 Create a cartesian product range of integer ranges from given integers.
 
template<typename I , size_t N, typename EnableIf = std::enable_if_t<std::is_integral_v<I>, int>>
auto itertools::product_range (std::array< I, N > const &idx_arr)
 Create a cartesian product range of integer ranges from an array of integers.
 
template<typename... Is, typename EnableIf = std::enable_if_t<(std::is_integral_v<Is> and ...), int>>
auto itertools::product_range (std::tuple< Is... > const &idx_tpl)
 Create a cartesian product range of integer ranges from a tuple of integers.
 

Function Documentation

◆ foreach()

template<typename F >
void itertools::foreach ( range const & rg,
F && f )

#include <itertools/range.hpp>

Apply a function to every element of an integer itertools::range.

// print out the first 10 squares
std::cout << i * i << " ";
});
A lazy range of integers that mimics a Python range.
Definition range.hpp:80
void foreach(range const &rg, F &&f)
Apply a function to every element of an integer itertools::range.
Definition range.hpp:402

Output:

1 4 9 16 25 36 49 64 81 100
Template Parameters
FCallable type.
Parameters
rgitertools::range object.
fCallable object to be applied to each element.

Definition at line 402 of file range.hpp.

◆ product_range() [1/3]

template<typename... Is, typename EnableIf = std::enable_if_t<(std::is_integral_v<Is> and ...), int>>
auto itertools::product_range ( Is... is)
nodiscard

#include <itertools/range.hpp>

Create a cartesian product range of integer ranges from given integers.

The given integers specify the excluded last values of the individual itertools::range objects. Each range starts at 0 and has a step size of 1.

for (auto [i1, i2] : product_range(2, 3)) {
std::cout << "(" << i1 << ", " << i2 << ")\n";
}
auto product_range(Is... is)
Create a cartesian product range of integer ranges from given integers.
Definition range.hpp:304

Output:

(0, 0)
(0, 1)
(0, 2)
(1, 0)
(1, 1)
(1, 2)
Template Parameters
IsInteger types.
Parameters
isLast values of the integer ranges (excluded).
Returns
Product (itertools::multiplied) range of integer ranges. See itertools::product and itertools::range.

Definition at line 304 of file range.hpp.

◆ product_range() [2/3]

template<typename I , size_t N, typename EnableIf = std::enable_if_t<std::is_integral_v<I>, int>>
auto itertools::product_range ( std::array< I, N > const & idx_arr)
nodiscard

#include <itertools/range.hpp>

Create a cartesian product range of integer ranges from an array of integers.

The integers in the given array specify the excluded last values of the individual itertools::range objects. Each range starts at 0 and has a step size of 1.

for (auto [i1, i2] : product_range(std::array{2, 3})) {
std::cout << "(" << i1 << ", " << i2 << ")\n";
}

Output:

(0, 0)
(0, 1)
(0, 2)
(1, 0)
(1, 1)
(1, 2)
Template Parameters
IInteger type.
NNumber of elements in the array.
Parameters
idx_arrArray containing the excluded last values of the integer ranges.
Returns
Product (itertools::multiplied) range of integer ranges. See itertools::product and itertools::range.

Definition at line 378 of file range.hpp.

◆ product_range() [3/3]

template<typename... Is, typename EnableIf = std::enable_if_t<(std::is_integral_v<Is> and ...), int>>
auto itertools::product_range ( std::tuple< Is... > const & idx_tpl)
nodiscard

#include <itertools/range.hpp>

Create a cartesian product range of integer ranges from a tuple of integers.

The integers in the given tuple specify the excluded last values of the individual itertools::range objects. Each range starts at 0 and has a step size of 1.

for (auto [i1, i2] : product_range(std::make_tuple(2, 3))) {
std::cout << "(" << i1 << ", " << i2 << ")\n";
}

Output:

(0, 0)
(0, 1)
(0, 2)
(1, 0)
(1, 1)
(1, 2)
Template Parameters
IsInteger types.
Parameters
idx_tplTuple containing the excluded last values of the integer ranges.
Returns
Product (itertools::multiplied) range of integer ranges. See itertools::product and itertools::range.

Definition at line 345 of file range.hpp.