View source code
Display the source code in std/algorithm/iteration.d from which thispage was generated on github.
Report a bug
If you spot a problem with this page, click here to create aBugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinglocal clone.

std.algorithm.iteration.Permutations/permutations - multiple declarations

Function permutations

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

Permutations!Range permutations(Range)(
  Range r
);

Parameters

NameDescription
Range the range type
r the random access range to find the permutations for.

Returns

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.

See Also

nextPermutation.

Example

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]]));

Struct Permutations

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

struct Permutations(Range);

Constructors

NameDescription
this (r)

Properties

NameTypeDescription
empty[get] bool
front[get] auto

Methods

NameDescription
popFront ()
save ()

Parameters

NameDescription
Range the range type
r the random access range to find the permutations for.

Returns

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.

See Also

nextPermutation.

Example

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]]));

Authors

Andrei Alexandrescu

License

Boost License 1.0.