On 03/12/2012 08:06 AM, Magnus Lie Hetland wrote: > On 2012-03-12 13:56:15 +0000, bearophile said: > >> It's not a bug, char is meant to be a UTF-8. > > Right. > >> Two workarounds: > > Thanks. I'm doing the sorting in a template, so this won't work -- but I > guess I just can't use char as a type parameter to my template either, > then :) >
You can use isNarrowString to either disallow or provide special implementation for narrow strings (char[] and wchar[]):
import std.traits; void foo(T)(T t) if (!isNarrowString!T) { // ... } void bar(T)(T t) { static if (isNarrowString!T){ // ... } else { // ... } } void main() { char[] sc; dchar[] sd; // foo(sc); // <-- compilation error foo(sd); bar(sc); bar(sd); } Ali