www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Different types

In my code I sometimes use the pattern:

!is(T1 == T2)

I have counted more than 200 usages of such pattern in 
dmd/Phobos, see the attach here:
http://d.puremagic.com/issues/attachment.cgi?id=1242

So I suggest to allow the handy syntax (similar to the "!is" and 
"!in" syntax):

is(T1 != T2)


The enhancement request:
http://d.puremagic.com/issues/show_bug.cgi?id=10816

- - - - - - - - - - - - - - - - - - -

But Timon has reminded us of a complexity I didn't think/know 
about, look at the last assert:


void main() {
     alias T1 = int;
     alias T2 = int;
     alias T3 = double;
     static assert(is(T1 == T2));
     static assert(!is(T1 == T3));
     //static assert(!is(T1 == T4)); // Error: undefined 
identifier T4
     static assert(!is(T4 == T1));   // OK?
}


Is that behavour by design? If it's unwanted then I'll open a bug 
report and I suggest to fix it, to generate errors in both the 
last two asserts.

If that behavour is desired or it can't be fixed, then an 
alternative solution is to support equality and disequality 
syntax of naked types:

bool b1 = T1 == T2;
bool b2 = T1 != T3;

With this syntax all the T1, T2 and T3 types must exist. Once 
this syntax is present the older is(T1==T2) should be deprecated.

- - - - - - - - - - - - - - - - - - -

Note: perhaps it's also meaningful to support comparisons < >:


class Klass1 {}
class Klass2 : Klass1 {}
enum bool b1 = is(Klass1 < Klass2);

alias T1 = Tuple!(int, "x");
alias T2 = Tuple!(int);
enum bool b2 = is(T1 < T2);


But this introduces complexities that I think are better left to 
a separate discussion and enhancement request.

Bye,
bearophile
Aug 14 2013