Could I get some help with a trivial question, I'm sure? How do pass a slice as a range? This code:

import std.algorithm; // permutations
import std.range; // replicate
import std.stdio; // writeln

int main()
{
    char[] as = replicate(['a'], 5);
    as[0] = 'b';
    foreach (perm; as.permutations)
        writeln(perm);
}

appears to complain (actual error below) that 'as' is not a range.

Using the slice trick "as[]" from:

https://forum.dlang.org/thread/oxohqaicmpteesugs...@forum.dlang.org

doesn't help either. Something obvious I'm missing, I hope.

perm.d:8:26: error: none of the overloads of template ‘std.algorithm.iteration.permutations’ are callable using argument types ‘!()(char[])’
    8 |         foreach (perm; as.permutations)
      |                          ^
/usr/lib/gcc/x86_64-linux-gnu/13/include/d/std/algorithm/iteration.d:7919:20: 
note: Candidate is: ‘permutations(Range)(Range r)’
     with `Range = char[]`
  must satisfy the following constraint:
`       isRandomAccessRange!Range`
 7919 | Permutations!Range permutations(Range)(Range r)
      |                    ^

Reply via email to