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

Table of Contents

build

‍This is the homepage of TRIQS/itertools 1.3.0. The source code can be found on GitHub.

#include <vector>
using namespace itertools;
int main() {
// ===== Integer ranges =====
for(int i: range(10)) { /* 0, 1, .., 9 */ }
for(int i: range(2, 10, 2)) { /* 2, 4, 6, 8 */ }
for (auto [i, j] : product_range(5, 5)) {
/* (0, 0), (0, 1), .. (0, 4),
(1, 0), (1, 2), .. (1, 4),
...
(4, 0), (4, 2), .. (4, 4) */
}
// ===== Adapted ranges =====
std::vector<char> Vc{'a', 'b', 'c'};
for (auto [i, c] : enumerate(Vc)) {
/* (0, 'a'), (1, 'b'), (2, 'c') */
}
std::vector<double> Vd{2.0, 4.0, 1.0};
for (auto [c, d] : zip(Vc, Vd)) {
/* ('a', 2.0), ('b', 4.0), ('c', 1.0) */
}
for (auto [c, d] : product(Vc, Vd)) {
/* ('a', 2.0), ('a', 4.0), ('a', 1.0),
('b', 2.0), ('b', 4.0), ('b', 1.0),
('c', 2.0), ('c', 4.0), ('c', 1.0) */
}
for (auto x : transform(Vd, [](auto d){ return d * d; })) {
/* 4.0, 16.0, 1.0 */
}
}
A lazy range of integers that mimics a Python range.
Definition range.hpp:80
auto product_range(Is... is)
Create a cartesian product range of integer ranges from given integers.
Definition range.hpp:304
auto transform(R &&rg, F lambda)
Lazy-transform a given range by applying a unary callable object to every element of the original ran...
itertools::multiplied< Rs... > product(Rs &&...rgs)
Lazy-multiply a given number of ranges by forming their cartesian product.
Definition product.hpp:240
zipped< Rs... > zip(Rs &&...rgs)
Lazy-zip ranges together (similar to Python's zip).
Definition zip.hpp:218
enumerated< R > enumerate(R &&rg)
Lazy-enumerate a given range (similar to Python's enumerate).
Provides a small subset of the ranges and views from std::ranges.

itertools defines a small subset of the ranges and views from std::ranges. The main purpose of the library is to provide lazy ranges

  • that can be iterated over in range-based for loops (see example above) and
  • that can be used to make lazy views of multidimensional arrays
    #include <nda/nda.hpp>
    int main() {
    // create a 10 x 10 matrix
    auto A = nda::matrix<int>::rand(10, 10);
    // create a view on the 5 x 10 submatrix consisting of every other row
    auto sub_A = A(nda::range(0, 10, 2), nda::range::all);
    }
    Visit TRIQS/nda for more details.

Note that nearly all of the functionality (and much more) of itertools is also provided by std::ranges or Eric Niebler's range-v3 library. We therefore recommend to use one of those, if you have a choice.

Where to start?

The Installation section tells you how to get the library and make it available on your system.

Integration in C++ projects explains how to integrate itertools in your own C++ code.

Then, you can start with the Examples section to get an overview of the library's features and how it compares with std::ranges.

Furthermore, we provide a detailed reference API Documentation to answer your questions.

If you experience any problem with the library, you can post an Issue on GitHub.