Add support implicit conversion between types
Simen Kjaeraas
simen.kjaras at gmail.com
Sat Sep 7 06:02:14 PDT 2013
On 2013-09-06, 15:57, ilya-stromberg wrote:
> On Friday, 6 September 2013 at 13:39:20 UTC, deadalnix wrote:
>> You don't want a keyword for that. Something obscure and ugly is
>> required.
>
> C# have operator overloading for this.
>
> We can use, for example, "opImplicitRightCast"
>
> struct Foo
> {
> Foo opImplicitRightCast(T)(T from);
> }
It's a bit weird in D though, as operators are instance methods, and
opImplicitRightCast (or opImplicitCastFrom, which is the name used in
discussions before, see WalterAndrei.pdf from back when dinosaurs roamed
the
earth) should definitely not be an instance method but a static one.
That said, I belive opImplicitCastFrom is The Right Solution™. It's
explicit,
it's a bit ugly, but not so much it hurts.
--
Simen
More information about the Digitalmars-d
mailing list