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

mw mingwu at gmail.com
Wed Jun 10 22:47:49 UTC 2020


Hi,

I'm trying to follow this doc on typedef:

https://dlang.org/library/std/typecons/typedef.html

--------------------------------
import std.typecons;
import std.stdio;

alias MyInt = Typedef!int;

void f(MyInt mi) {}

void main() {
   MyInt a = 2;
   MyInt b = 3;
   f(a + b);
}
--------------------------------

td.d(14,4): Error: function td.f(Typedef!(int, 0, null) mi) is 
not callable using argument types (int)
td.d(14,4):        cannot pass argument a.opBinary(b) of type int 
to parameter Typedef!(int, 0, null) mi

Naturally I've expected `a + b` will have the same type as MyInt 
(not the underlying type int).

Is this a typedef overlook, or it's a feature by design?

If it's by design what's the reason behind?

Thanks.


More information about the Digitalmars-d mailing list