Macro itertools::iproduct

source ·
macro_rules! iproduct {
    (@flatten $I:expr,) => { ... };
    (@flatten $I:expr, $J:expr, $($K:expr,)*) => { ... };
    ($I:expr) => { ... };
    ($I:expr, $J:expr) => { ... };
    ($I:expr, $J:expr, $($K:expr),+) => { ... };
}
Expand description

Create an iterator over the “cartesian product” of iterators.

Iterator element type is like (A, B, ..., E) if formed from iterators (I, J, ..., M) with element types I::Item = A, J::Item = B, etc.

// Iterate over the coordinates of a 4 x 4 x 4 grid
// from (0, 0, 0), (0, 0, 1), .., (0, 1, 0), (0, 1, 1), .. etc until (3, 3, 3)
for (i, j, k) in iproduct!(0..4, 0..4, 0..4) {
   // ..
}