nextPermutation: why possible for dchar but not for char?

monarch_dodra monarchdodra at gmail.com
Sun Dec 29 02:02:29 PST 2013


On Saturday, 28 December 2013 at 23:38:38 UTC, Ivan Kazmenko 
wrote:
> Ouch, is it an exception hard-coded into the language itself?  
> I thought it's just the nextPermutation's parameter type 
> restrictions which don't allow "char []"...

No, a "char[]" is just a "char[]" as far as the language is 
concerned[1]. However, for the *phobos* range abstraction, (the 
front/popFront/empty) primitives, a char[] is a range of dchars. 
Once you've defined char[] as such a range, it affects all of 
phobos.

It's critiqued every now and then, but overall, it has proven to 
increase code correctness, at the cost (sometimes) of rejecting 
code that might be incorrect. Long story short: If you want to 
handle UTF, you have to handle it *explicitly*. *I* think it is a 
good compromise.

[1] the *only* place (AFAIK) that dmd looks at a string as a 
range of dchars is in a "foreach(dchar c; s)" loop. But even 
then, if you don't specify "dchar", then c will default to char.


More information about the Digitalmars-d-learn mailing list