digitalmars.D.learn - overloading InExpression
- Vlad Levenfeld (4/4) Jul 02 2014 Is this possible?
- Dicebot (11/11) Jul 02 2014 struct S
- Vlad Levenfeld (2/13) Jul 02 2014 Thanks! I wonder, why the _r and lack of documentation?
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (8/23) Jul 02 2014 I think it is the old syntax, meaning "this is the overload for when an
- Kozzi11 (15/29) Jul 02 2014 Maybe something from old days? But in current
- Dicebot (3/7) Jul 02 2014 Yep, I think it is D1 legacy approach. opBinary should be more
- bearophile (5/7) Jul 02 2014 I hope the usage of the old operator overloading functions will
- H. S. Teoh via Digitalmars-d-learn (12/27) Jul 02 2014 Don't use opIn_r, that's a relic from D1. Instead, use this:
- Vlad Levenfeld (3/3) Jul 02 2014 Ah yes I never noticed that "in" was in the binary op table. In
Is this possible? The documentation for std.container lists "in" as an operator in the container API but only associative arrays actually seem to support it.
Jul 02 2014
struct S { int opIn_r(int key) { return key*2; } } void main() { assert((42 in S.init) == 84); }
Jul 02 2014
On Wednesday, 2 July 2014 at 14:14:57 UTC, Dicebot wrote:struct S { int opIn_r(int key) { return key*2; } } void main() { assert((42 in S.init) == 84); }Thanks! I wonder, why the _r and lack of documentation?
Jul 02 2014
On 07/02/2014 07:35 AM, Vlad Levenfeld wrote:On Wednesday, 2 July 2014 at 14:14:57 UTC, Dicebot wrote:I think it is the old syntax, meaning "this is the overload for when an S object is on the right-hand side".struct S { int opIn_r(int key) { return key*2; } } void main() { assert((42 in S.init) == 84); }Thanks! I wonder, why the _rand lack of documentation?It appears in the binary operator table: http://dlang.org/operatoroverloading.html#Binary Also see the section 'Inclusion query by opBinaryRight!"in"' here: http://ddili.org/ders/d.en/operator_overloading.html Ali
Jul 02 2014
On Wednesday, 2 July 2014 at 14:35:55 UTC, Vlad Levenfeld wrote:On Wednesday, 2 July 2014 at 14:14:57 UTC, Dicebot wrote:Maybe something from old days? But in current <a href="http://dlang.org/operatoroverloading.html#Binary" target="_blank">doc</a> there is a opBinary: struct S { int opBinaryRight(string op : "in")(int key) { return key*2; } } void main() { assert((42 in S.init) == 84); }struct S { int opIn_r(int key) { return key*2; } } void main() { assert((42 in S.init) == 84); }Thanks! I wonder, why the _r and lack of documentation?
Jul 02 2014
On Wednesday, 2 July 2014 at 15:36:23 UTC, Kozzi11 wrote:Yep, I think it is D1 legacy approach. opBinary should be more appropriate.Thanks! I wonder, why the _r and lack of documentation?Maybe something from old days? But in current <a href="http://dlang.org/operatoroverloading.html#Binary" target="_blank">doc</a> there is a opBinary:
Jul 02 2014
Dicebot:Yep, I think it is D1 legacy approach. opBinary should be more appropriate.I hope the usage of the old operator overloading functions will generate deprecation messages soon. Bye, bearophile
Jul 02 2014
On Wed, Jul 02, 2014 at 02:35:54PM +0000, Vlad Levenfeld via Digitalmars-d-learn wrote:On Wednesday, 2 July 2014 at 14:14:57 UTC, Dicebot wrote:Don't use opIn_r, that's a relic from D1. Instead, use this: struct S { int opBinaryRight(string op)(int key) if (op == "in") { return key*2; } } T -- I think Debian's doing something wrong, `apt-get install pesticide', doesn't seem to remove the bugs on my system! -- Mike Dresserstruct S { int opIn_r(int key) { return key*2; } } void main() { assert((42 in S.init) == 84); }Thanks! I wonder, why the _r and lack of documentation?
Jul 02 2014
Ah yes I never noticed that "in" was in the binary op table. In my defense, searching for "in" usually yields too many results to be useful. Thanks to everyone for your help!
Jul 02 2014