About std.string.representation

bearophile bearophileHUGS at lycos.com
Sun May 5 04:21:21 PDT 2013


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


More information about the Digitalmars-d-learn mailing list