May 05, 2013 About std.string.representation | ||||
|---|---|---|---|---|
| ||||
Is it possible to have a transparent (by reference) std.string.representation?
It's handy to modify the chars, like with permutations:
import std.stdio: writeln;
import std.range: nextPermutation;
import std.string: representation;
void main() {
char[] perm = "abcd".dup;
do {
writeln(perm);
} while (nextPermutation(representation(perm)));
}
Currently to permute them you have to use dchars:
import std.stdio: writeln;
import std.range: nextPermutation;
void main() {
dchar[] perm = "abcd"d.dup;
do {
writeln(perm);
} while (nextPermutation(perm));
}
Or to use casts and ubytes:
import std.stdio: writeln;
import std.range: nextPermutation;
void main() {
ubyte[] perm = cast(ubyte[])("abcd".dup);
do {
writeln(cast(char[])perm);
} while (nextPermutation(perm));
}
Thank you,
bye,
bearophile
| ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply