opEquals among types

Jacob Carlborg doob at me.com
Sat Mar 6 06:00:10 PST 2010


On 3/5/10 21:04, bearophile wrote:
> This D2 program compiles and works correctly:
>
> import std.c.stdio: printf;
> auto add(T1, T2)(T1 x, T2 y) {
>      if (!is(T1 == T2))
>          printf("Different types\n");
>      return x + y;
> }
> void main() {}
>
>
> But do you know why D2 needs that is() there? Can't it be removed, like this? (doesn't work):
>
> import std.c.stdio: printf;
> auto add(T1, T2)(T1 x, T2 y) {
>      if (T1 != T2)
>          printf("Different types\n");
>      return x + y;
> }
> void main() {}
>
>
> The difference for the programmer is not big, but the second is a little shorter/cleaner.
>
> Bye and thank you,
> bearophile

I think that this has been up for discussion before and if I recall 
correctly the answer was that it would make the compiler more complicated.


More information about the Digitalmars-d-learn mailing list