Special Type Challenge
Jonathan Marler via Digitalmars-d
digitalmars-d at puremagic.com
Fri Feb 6 20:28:01 PST 2015
On Saturday, 7 February 2015 at 03:48:24 UTC, Adam D. Ruppe wrote:
> wrote:
>> b = -256;
>
> that won't fit in a byte btw.
Woops, I typed that example too fast :)
>
> The rest of the assignment stuff is easy. I'd prolly even do it
> with a template:
>
> this(T)(T t) { this.opAssign(t); } // for construction
> Byte opAssign(T)(T t) if(T.sizeof == 1) { // for other
> assignment
> data_holder = cast(typeof(data_holder) t);
> }
>
> and that should do it.
This code is almost exactly what I came up with. But what about
the function problem?
void echo(Byte b);
echo('c'); // won't work
I can't figure out a way to make this work (without making echo a
template). If D supported implicit conversions from built-in
types to user types then it could work. Do you know if D might
support that later or if there's a reason for not supporting it?
More information about the Digitalmars-d
mailing list