Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
August 13, 2013 [Issue 10816] New: Support for is(T1 != T2) syntax | ||||
---|---|---|---|---|
| ||||
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 --- Comment #0 from bearophile_hugs@eml.cc 2013-08-13 07:03:37 PDT --- 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: ------- |
August 13, 2013 [Issue 10816] Support for is(T1 != T2) syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=10816 timon.gehr@gmx.ch changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |timon.gehr@gmx.ch --- Comment #1 from timon.gehr@gmx.ch 2013-08-13 07:29:42 PDT --- 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: ------- |
August 13, 2013 [Issue 10816] Support for is(T1 != T2) syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=10816 Dicebot <public@dicebot.lv> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |public@dicebot.lv --- Comment #2 from Dicebot <public@dicebot.lv> 2013-08-13 08:49:44 PDT --- 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: ------- |
August 13, 2013 [Issue 10816] Support for is(T1 != T2) syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=10816 --- Comment #3 from timon.gehr@gmx.ch 2013-08-13 09:01:05 PDT --- (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? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 13, 2013 [Issue 10816] Support for is(T1 != T2) syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=10816 --- Comment #4 from Dicebot <public@dicebot.lv> 2013-08-13 09:07:06 PDT --- (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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 13, 2013 [Issue 10816] Support for is(T1 != T2) syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=10816 --- Comment #5 from bearophile_hugs@eml.cc 2013-08-13 09:36:29 PDT --- (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? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation