Permutations

Lazily computes all permutations of r using Heap's algorithm.

Constructors

this
this(Range r)

Members

Functions

popFront
void popFront()
save
auto save()

Properties

empty
bool empty [@property getter]
front
auto front [@property getter]

Parameters

Range

the range type

Return Value

A forward range of elements of which are an std.range.indexed view into r.

Note: The elements of the resulting range reuse the same internal buffer of permutations, so each element is invalidated by popFront. If copies of intermediate permutations are desired, they need to be individually copied, such as using .map!(e => e.array) to save them in individual, independent arrays.

Examples

import std.algorithm.comparison : equal;
import std.range : iota;
assert(equal!equal(iota(3).permutations,
    [[0, 1, 2],
     [1, 0, 2],
     [2, 0, 1],
     [0, 2, 1],
     [1, 2, 0],
     [2, 1, 0]]));

See Also

Meta