nextPermutation: why possible for dchar but not for char?

Ivan Kazmenko gassa at mail.ru
Sat Dec 28 14:55:36 PST 2013


Another quick question, two of them.

1. This is a minimal example of trying the permutations of a 
character array.

-----
import std.algorithm;
void main () {
     char [] a;
     do { } while (nextPermutation(a));
}
-----

This gives a compile error.  However, it works when I change 
"char [] a" to "dchar [] a".  Why?

I understand that permuting a char [] array might be wrong way to 
go when dealing with Unicode.  But what if, at this point of the 
program, I am sure I'm dealing with ASCII and just want 
efficiency?  Should I convert to ubyte [] somehow - what's the 
expected way then?  The "cast (ubyte [])" works, but "to!(ubyte 
[])" fails at runtime, expecting a string representation of the 
array, not its raw contents.

2. Why does nextPermutation hang up for empty arrays?  I suppose 
that's a bug?

Ivan Kazmenko.


More information about the Digitalmars-d-learn mailing list