Auto-casting in range based functions?

Andrew Stanton refefer at gmail.com
Sun May 13 10:49:00 PDT 2012


I have been playing around with D as a scripting tool and have 
been running into the following issue:

-----------------------------------
import std.algorithm;

struct Delim {
     char delim;
     this(char d) {
         delim = d;
     }
}

void main() {
     char[] d = ['a', 'b', 'c'];
     auto delims = map!Delim(d);
}

/*
Compiling gives me the following error:
/usr/include/d/dmd/phobos/std/algorithm.d(382): Error: 
constructor test.Delim.this (char d) is not callable using 
argument types (dchar)
/usr/include/d/dmd/phobos/std/algorithm.d(382): Error: cannot 
implicitly convert expression ('\U0000ffff') of type dchar to char

*/

-----------------------------------

As someone who most of the time doesn't need to handle unicode, 
is there a way I can convince these functions to not upcast char 
to dchar?  I can't think of a way to make the code more explicit 
in its typing.


More information about the Digitalmars-d-learn mailing list