Skip to content

A C++ library that provides functionality to create and adapt C++ ranges.

License

Notifications You must be signed in to change notification settings

TRIQS/itertools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2bb4da2 · May 26, 2024
Apr 24, 2024
Apr 24, 2024
May 16, 2024
Apr 2, 2024
May 16, 2024
Jan 30, 2024
Mar 5, 2024
May 16, 2024
Feb 17, 2022
Apr 2, 2024
Oct 30, 2020
Jul 26, 2023
May 26, 2024
Feb 17, 2022
Mar 22, 2024
May 18, 2020
Apr 27, 2020
Apr 24, 2024
Jul 29, 2019

Repository files navigation

build

itertools

itertools is a C++ library that provides functionality to create and adapt C++ ranges.

A reference documentation based on Doxygen is provided at triqs.github.io/itertools.

Simple Example

#include <itertools/itertools.hpp>
#include <vector>

using namespace itertools;

int main(){

  // ===== Ranges of numbers =====

  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) */
  }

  // ===== Adapting 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 */
  }

}

For further examples we refer the users to our tests.