|
TRIQS/itertools 2.0.0
C++ range library
|
Range adapting functions take one or more existing ranges and return lazy Adapted ranges that can be iterated over.
Lazy means that new elements are produced on the fly whenever they are needed instead of being precomputed when the range is created.
Functions | |
| template<typename R> | |
| enumerated< R > | itertools::enumerate (R &&rg) |
| Lazy-enumerate a given range (similar to Python's enumerate). | |
| template<typename R, size_t N> | |
| auto | itertools::make_product (std::array< R, N > &arr) |
| Create a cartesian product range from an array of ranges. | |
| template<typename R, size_t N> | |
| auto | itertools::make_product (std::array< R, N > const &arr) |
| Const overload of make_product(std::array<R, N> &). | |
| template<typename... Rs> | |
| itertools::multiplied< Rs... > | itertools::product (Rs &&...rgs) |
| Lazy-multiply a given number of ranges by forming their cartesian product. | |
| template<typename R> | |
| itertools::multiplied_vec< R > | itertools::product_vec (std::vector< R > rgs) |
| Lazy-multiply a vector of homogeneous ranges by forming their cartesian product. | |
| template<typename R> | |
| sliced< R > | itertools::slice (R &&rg, std::ptrdiff_t start_idx, std::ptrdiff_t end_idx) |
| Lazy-slice a given range. | |
| template<typename R> | |
| strided< R > | itertools::stride (R &&rg, std::ptrdiff_t stride) |
| Lazy-stride through a given range. | |
| template<typename R, typename F> | |
| auto | itertools::transform (R &&rg, F lambda) |
| Lazy-transform a given range by applying a unary callable object to every element of the original range. | |
| template<typename... Rs> | |
| zipped< Rs... > | itertools::zip (Rs &&...rgs) |
| Lazy-zip ranges together (similar to Python's zip). | |
|
nodiscard |
#include <itertools/enumerate.hpp>
Lazy-enumerate a given range (similar to Python's enumerate).
Each element in the original range is assigned an index, starting from zero. This function returns an iterable lazy object (an itertools::enumerated range), which iterates over tuples consisting of the index and the value of the dereferenced iterator of the original range:
Output:
See also std::ranges::views::enumerate.
| R | Range type. |
| rg | Range to enumerate. |
Definition at line 162 of file enumerate.hpp.
|
nodiscard |
#include <itertools/product.hpp>
Create a cartesian product range from an array of ranges.
| R | Range type. |
| N | Number of ranges. |
| arr | Array of ranges. |
Definition at line 473 of file product.hpp.
|
nodiscard |
#include <itertools/product.hpp>
Lazy-multiply a given number of ranges by forming their cartesian product.
An arbitrary number of ranges are multiplied together into a cartesian product range. They are traversed such that the last range is traversed the fastest (see the example below).
The number of elements in a product range is equal to the product of the sizes of the given ranges.
This function returns an iterable lazy object, which can be used in range-based for loops:
Output:
See also std::ranges::views::cartesian_product.
| Rs | Range types. |
| rgs | Ranges to be used. |
Definition at line 413 of file product.hpp.
|
nodiscard |
#include <itertools/product.hpp>
Lazy-multiply a vector of homogeneous ranges by forming their cartesian product.
Similar to itertools::product, but takes a vector of homogeneous ranges instead of a variadic number of potentially heterogeneous ranges. This allows for a runtime-determined number of ranges.
They are traversed such that the last range is traversed the fastest (see the example below). The number of elements in a product range is equal to the product of the sizes of the given ranges. This function returns an iterable lazy object, which can be used in range-based for loops:
Output:
| R | Range type. |
| rgs | Vector of ranges to be used. |
Definition at line 454 of file product.hpp.
|
nodiscard |
#include <itertools/slice.hpp>
Lazy-slice a given range.
Only the part of the given range between the start_idx and the end_idx is taken into account:
This function returns an iterable lazy object, which can be used in range-based for loops:
Output:
| R | Range type. |
| rg | Range to be sliced. |
| start_idx | Index where the slice starts. |
| end_idx | Index of the first element past the end of the sliced range (excluded). |
|
nodiscard |
#include <itertools/stride.hpp>
Lazy-stride through a given range.
Only every Nth element of the original range is taken into account. If the given stride (N) is <= 0, an exception is thrown.
This function returns an iterable lazy object, which can be used in range-based for loops:
Output:
See also std::ranges::views::stride.
| R | Range type. |
| rg | Original range. |
| stride | Number of elements to skip when incrementing. |
Definition at line 167 of file stride.hpp.
|
nodiscard |
#include <itertools/transform.hpp>
Lazy-transform a given range by applying a unary callable object to every element of the original range.
The value type of the transformed range depends on the return type of the callable.
This function returns an iterable lazy object (an itertools::transformed range), which can be used in range-based for loops:
Output:
See also std::ranges::views::transform.
| R | Range type. |
| F | Callable type. |
| rg | Range to transform. |
| lambda | Callable to be applied to the given range. |
Definition at line 183 of file transform.hpp.
|
nodiscard |
#include <itertools/zip.hpp>
Lazy-zip ranges together (similar to Python's zip).
An arbitrary number of ranges are zipped together into a tuple. The zipped range will have as many elements as the shortest given range.
This function returns an iterable lazy object, which can be used in range-based for loops:
Output:
See also std::ranges::views::zip.
| Rs | Range types. |
| rgs | Ranges to zip. |