D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10816 - Support for is(T1 != T2) syntax
Summary: Support for is(T1 != T2) syntax
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-13 07:03 UTC by bearophile_hugs
Modified: 2024-12-13 18:10 UTC (History)
2 users (show)

See Also:


Attachments
Hundreds of usage cases found in dmd/Phobos (19.92 KB, text/plain)
2013-08-13 07:03 UTC, bearophile_hugs
Details

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2013-08-13 07:03:37 UTC
Created attachment 1242 [details]
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);

--------------------------
Comment 1 timon.gehr 2013-08-13 07:29:42 UTC
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.
Comment 2 Dicebot 2013-08-13 08:49:44 UTC
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.
Comment 3 timon.gehr 2013-08-13 09:01:05 UTC
(In reply to comment #2)
> 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?
Comment 4 Dicebot 2013-08-13 09:07:06 UTC
(In reply to comment #3)
> 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.
Comment 5 bearophile_hugs 2013-08-13 09:36:29 UTC
(In reply to comment #1)

> 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?
Comment 6 dlangBugzillaToGithub 2024-12-13 18:10:15 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17603

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB