Typedef!int + Typedef!int => int? is this a typedef overlook, or it's a feature by design?

RazvanN razvan.nitu1305 at gmail.com
Thu Jun 11 04:21:05 UTC 2020


On Thursday, 11 June 2020 at 04:11:24 UTC, RazvanN wrote:

> I think it is an overlook and therefore a bug. The spec says 
> that the whole point of Typedef is to create a type that is 
> different from the typedefed one (otherwise you would end up 
> with a glorified alias). However the implementation simply 
> mixins a generic implementation of opBinary that uses the 
> underlying type [1]. The definition of opBinary has no idea 
> that it should wrap the result in another type [2].
>
> [1] 
> https://github.com/dlang/phobos/blob/master/std/typecons.d#L7472
> [2] 
> https://github.com/dlang/phobos/blob/master/std/typecons.d#L6836

The only solution I can come up with is to add an optional 
parameter called Wrapper to Proxy that defaults to the type of 
the first parameter. The opBinary function then will be modified 
to return Wrapper!ValueType if (is(Wrapper != ValueType)).


More information about the Digitalmars-d mailing list