www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10816] New: Support for is(T1 != T2) syntax

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10816

           Summary: Support for is(T1 != T2) syntax
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



Created an attachment (id=1242)
Hundreds of usage cases found in dmd/Phobos

In Phobos I have counted about 240 cases (even if some of them are possibly
false positives, see the attach) of usages of the pattern:

!is(T1 == T2)

So I suggest to add to D a handy syntax like this (that in past sometimes I
even have used by mistake):

is(T1 != T2)

It's similar to the handy "!is" and "!in" syntaxes.

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

Extra: in some cases you can even think about a comparison, but this is left to
other enhancement requests:

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);

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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 13 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10816


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr gmx.ch



What is the meaning of is(T1!=T2) ?

Is it

!is(T1==T2)

or

is(T1) && !is(T1==T2)

IMO the way to go is to use T1==T2 and T1!=T2. (In this case, both T1 and T2
should be valid types.)

---

Extra: What would be the difference to is(T1:T2) ? I think this would again
make more sense without 'is': T1<T2.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 13 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10816


Dicebot <public dicebot.lv> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |public dicebot.lv



I like the idea. Both because of consistency and because that '!' near to 'i'
is so hard to notice.

 Timon

I don't think "is(T1) && !is(T1==T2)" is any useful. It will make "is(T1 != T2)
return false for invalid T1 which is rather surprising. I can't imagine the use
case for it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 13 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10816





 I like the idea. Both because of consistency and because that '!' near to 'i'
 is so hard to notice.
 
  Timon
 
 I don't think "is(T1) && !is(T1==T2)" is any useful. It will make "is(T1 != T2)
 return false for invalid T1 which is rather surprising. I can't imagine the use
 case for it.
Are you aware that is(T1==T2) gives false for invalid T1 and error for invalid T2? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 13 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10816





 Are you aware that is(T1==T2) gives false for invalid T1 and error for invalid
 T2?
Was aware about the former, not about the latter. But I don't see how it is relevant. When i compare types via is(T1 == T2), information that matters is "are those two the same?". It does not matter why are they not the same. Same goes for is(T1 != T2), but other way around - "are those types not the same"? Making "!is(T1 != T2) != is(T1 == T2)" breaks common sense quite a lot in my opinion. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 13 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10816






 What is the meaning of is(T1!=T2) ?
 
 Is it
 
 !is(T1==T2)
 
 or
 
 is(T1) && !is(T1==T2)
The most important use case is to test if two already existing types differ.
 IMO the way to go is to use T1==T2 and T1!=T2. (In this case, both T1 and T2
 should be valid types.)
I agree. But I think this is for another enhancement request. Do you want to open it? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 13 2013