digitalmars.D - Proposal - disallow overloading of opIn
- Jarrett Billingsley (7/7) Jun 20 2006 By that, I mean just the "regular" form of opIn, and only allow overload...
- Andrei Khropov (4/13) Jun 21 2006 I agree
- Bill Baxter (9/16) Jun 21 2006 What if you had a Set class and you wanted to override its opIn's to ret...
By that, I mean just the "regular" form of opIn, and only allow overloading of opIn_r. Why? Well, 'in' doesn't make sense if you reverse it; that is, "array in 4" makes no sense while "4 in array" does. Just from a cursory glance at opover.c, this should not be hard to implement - just have InExp::opId() return NULL. It doesn't look like anything depends on the result of opId() being non-NULL.
Jun 20 2006
Jarrett Billingsley wrote:By that, I mean just the "regular" form of opIn, and only allow overloading of opIn_r. Why? Well, 'in' doesn't make sense if you reverse it; that is, "array in 4" makes no sense while "4 in array" does. Just from a cursory glance at opover.c, this should not be hard to implement - just have InExp::opId() return NULL. It doesn't look like anything depends on the result of opId() being non-NULL.I agree -- AKhropov
Jun 21 2006
In article <e7a9gf$119s$1 digitaldaemon.com>, Jarrett Billingsley says...By that, I mean just the "regular" form of opIn, and only allow overloading of opIn_r. Why? Well, 'in' doesn't make sense if you reverse it; that is, "array in 4" makes no sense while "4 in array" does. Just from a cursory glance at opover.c, this should not be hard to implement - just have InExp::opId() return NULL. It doesn't look like anything depends on the result of opId() being non-NULL.What if you had a Set class and you wanted to override its opIn's to return something about set membership? "set in array" and "array in set" both make perfect sense in that case. One asks if the 'set' is a subset of elements in 'array', the other asks if the elements in 'array' are a subset of 'set'. If you only have the ability to override methods on your Set class then you'll want both opIn and opIn_r to make that work. If it doesn't make sense for a particular class then just don't provide the overload. Same goes for all overloadable operators.
Jun 21 2006