TRIQS/itertools 2.0.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.

#include <iostream>
int main() {
// print out the first 10 squares
itertools::foreach(itertools::range(1, 11), [](int i) { std::cout << i * i << " "; });
std::cout << "\n";
}
A lazy range of integers that mimics a Python range.
Definition range.hpp:64
void foreach(range const &rg, F &&f)
Apply a function to every element of an integer itertools::range.
Definition range.hpp:429
Provides a small subset of the ranges and views from std::ranges.

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 429 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.

#include <iostream>
int main() {
for (auto [i1, i2] : itertools::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:372

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 372 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.

It simply forwards the integers in the given array to itertools::product_range.

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 410 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.

It simply forwards the integers in the given tuple to itertools::product_range.

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 395 of file range.hpp.