Why no implicit cast operators?

Christophe Travert travert at phare.normalesup.org
Mon Aug 6 06:33:17 PDT 2012


"Tommi" , dans le message (digitalmars.D:174314), a écrit :
> In D it's not possible to make opCast operators implicit.
> Therefore I see no way of making "transparent wrappers"; like
> structs which could be used as a drop-in replacement for plain
> old data types.
> 
> E.g if I wanted to make a SafeInt struct, that behaves otherwise
> just like an int, but when operators like +=, *=, ++, -- etc are
> used with it, my custom SafeInt operators would check that
> there's no integer overflow. If you use alias this to _reveal_
> the internal int value of SafeInt, then that int value's default
> operators are used, and thus no overflow checking.
> 
> I find the lack of implicit casting a defect of the language.
> I hope that I'm wrong.

Does alias this not fullfill you goal?
http://dlang.org/class.html#AliasThis


More information about the Digitalmars-d mailing list