Re: "in" operator gives a pointer result from a test against an Associative Array?

2024-05-10 Thread Andy Valencia via Digitalmars-d-learn
On Friday, 10 May 2024 at 16:33:53 UTC, Nick Treleaven wrote: Arrays evaluate to true in boolean conditions if their `.ptr` field is non-null. This is bug-prone and I hope we can remove this in the next edition. ... A string literal's `.ptr` field is always non-null, because it is null-termina

Re: "in" operator gives a pointer result from a test against an Associative Array?

2024-05-10 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 10 May 2024 at 15:23:39 UTC, Andy Valencia wrote: On Friday, 10 May 2024 at 03:07:43 UTC, Steven Schveighoffer wrote: Yes, we say that a type has "truthiness" if it can be used in a condition (`while`, `if`, `assert`, etc). So if I may ask for one more small clarification... WRT "t

Re: "in" operator gives a pointer result from a test against an Associative Array?

2024-05-10 Thread Andy Valencia via Digitalmars-d-learn
On Friday, 10 May 2024 at 03:07:43 UTC, Steven Schveighoffer wrote: Yes, we say that a type has "truthiness" if it can be used in a condition (`while`, `if`, `assert`, etc). So if I may ask for one more small clarification... WRT "truthiness", I've observed that empty arrays are treated as fa

Re: "in" operator gives a pointer result from a test against an Associative Array?

2024-05-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 10 May 2024 at 01:00:09 UTC, Andy Valencia wrote: On Friday, 10 May 2024 at 00:40:01 UTC, Meta wrote: Yes. The reason for this is that it avoids having to essentially do the same check twice. If `in` returned a bool instead of a pointer, after checking for whether the element exists

Re: "in" operator gives a pointer result from a test against an Associative Array?

2024-05-09 Thread Andy Valencia via Digitalmars-d-learn
On Friday, 10 May 2024 at 00:40:01 UTC, Meta wrote: Yes. The reason for this is that it avoids having to essentially do the same check twice. If `in` returned a bool instead of a pointer, after checking for whether the element exists (which requires searching for the element in the associative

Re: "in" operator gives a pointer result from a test against an Associative Array?

2024-05-09 Thread Meta via Digitalmars-d-learn
On Friday, 10 May 2024 at 00:18:16 UTC, Andy Valencia wrote: tst7.d(6): Error: cannot implicitly convert expression `e in this.members` of type `bool*` to `bool` tst7.d(15): Error: template instance `tst7.Foo!uint` error instantiating I'm getting this for this bit of source (trimmed from the

"in" operator gives a pointer result from a test against an Associative Array?

2024-05-09 Thread Andy Valencia via Digitalmars-d-learn
tst7.d(6): Error: cannot implicitly convert expression `e in this.members` of type `bool*` to `bool` tst7.d(15): Error: template instance `tst7.Foo!uint` error instantiating I'm getting this for this bit of source (trimmed from the bigger code). I switched to this.members.get(e, false) and th

Re: I just discovered an alternative use of the `in`-operator

2020-08-09 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 6 August 2020 at 22:24:43 UTC, Paul Backus wrote: [1] https://dlang.org/spec/expression.html#is_expression Thanks

Re: I just discovered an alternative use of the `in`-operator

2020-08-07 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 07, 2020 at 09:02:03PM +, Per Nordlöw via Digitalmars-d-learn wrote: > On Thursday, 6 August 2020 at 22:24:43 UTC, Paul Backus wrote: > > [1] https://dlang.org/spec/expression.html#is_expression > > I bet there a several places in Phobos where this feature isn't but > could be use

Re: I just discovered an alternative use of the `in`-operator

2020-08-07 Thread aberba via Digitalmars-d-learn
On Friday, 7 August 2020 at 21:02:03 UTC, Per Nordlöw wrote: On Thursday, 6 August 2020 at 22:24:43 UTC, Paul Backus wrote: [1] https://dlang.org/spec/expression.html#is_expression I bet there a several places in Phobos where this feature isn't but could be used. I feel same. That there's a

Re: I just discovered an alternative use of the `in`-operator

2020-08-07 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 6 August 2020 at 22:24:43 UTC, Paul Backus wrote: [1] https://dlang.org/spec/expression.html#is_expression I bet there a several places in Phobos where this feature isn't but could be used.

Re: I just discovered an alternative use of the `in`-operator

2020-08-07 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 6 August 2020 at 22:24:43 UTC, Paul Backus wrote: [1] https://dlang.org/spec/expression.html#is_expression Thanks

Re: I just discovered an alternative use of the `in`-operator

2020-08-06 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 6 August 2020 at 21:50:06 UTC, Per Nordlöw wrote: I just discovered that the is-operator can be used as in template ElementType(R) { static if (is(typeof(R.init.front.init) T)) alias ElementType = T; else alias ElementType = void; } . Very powerful. Is this

I just discovered an alternative use of the `in`-operator

2020-08-06 Thread Per Nordlöw via Digitalmars-d-learn
I just discovered that the is-operator can be used as in template ElementType(R) { static if (is(typeof(R.init.front.init) T)) alias ElementType = T; else alias ElementType = void; } . Very powerful. Is this documented?

Re: I just discovered an alternative use of the `in`-operator

2020-08-06 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 6 August 2020 at 21:50:06 UTC, Per Nordlöw wrote: I just discovered that the is-operator can be used as in ... Doh, title should of course be I just discovered an alternative use of `is`-expressions.

Re: !in operator

2015-08-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, August 02, 2015 21:51:48 Ali Çehreli via Digitalmars-d-learn wrote: > Is my understanding below correct? Does any documentation need updating? > > Operator precedence table lists !in as an operator: > >http://wiki.dlang.org/Operator_precedence > > Operator overloading documentation d

!in operator

2015-08-02 Thread Ali Çehreli via Digitalmars-d-learn
Is my understanding below correct? Does any documentation need updating? Operator precedence table lists !in as an operator: http://wiki.dlang.org/Operator_precedence Operator overloading documentation does not mention it: http://dlang.org/operatoroverloading.html#binary However, 'a !in b

Re: How do formally you call the 'in' operator?

2011-09-24 Thread Ellery Newcomer
On 09/24/2011 01:18 PM, Andrej Mitrovic wrote: > Information about overloading opIn and opIn_r is missing from the > docs, so I'm writing that section. But I don't know what is the formal > name of this operator so I can put it in the title. Maybe I should > just name the tit

Re: How do formally you call the 'in' operator?

2011-09-24 Thread Jonathan M Davis
On Saturday, September 24, 2011 20:37:45 Andrej Mitrovic wrote: > Oh wait, I've just realized that opIn is actually the old way of using > that operator. The new way is using opBinary and string matching > instead. This is already described in the docs. > > I guess opIn and opIn_r are going away?

Re: How do formally you call the 'in' operator?

2011-09-24 Thread Andrej Mitrovic
Oh wait, I've just realized that opIn is actually the old way of using that operator. The new way is using opBinary and string matching instead. This is already described in the docs. I guess opIn and opIn_r are going away?

How do formally you call the 'in' operator?

2011-09-24 Thread Andrej Mitrovic
Information about overloading opIn and opIn_r is missing from the docs, so I'm writing that section. But I don't know what is the formal name of this operator so I can put it in the title. Maybe I should just name the title "Overloading the In Operator"?

Re: Overriding "in" operator

2011-03-04 Thread Ali Çehreli
On 03/04/2011 10:41 AM, Magnus Lie Hetland wrote: On 2011-03-04 18:08:08 +0100, spir said: Didn't even know 'in' can be defined with opBinary... I use opIn_r ('r' for right side, since the container stand on the right of the expression) everywhere, and it works fine. Huh. Cool. Works like a c

Re: Overriding "in" operator

2011-03-04 Thread Magnus Lie Hetland
On 2011-03-04 18:08:08 +0100, spir said: Didn't even know 'in' can be defined with opBinary... I use opIn_r ('r' for right side, since the container stand on the right of the expression) everywhere, and it works fine. Huh. Cool. Works like a charm. Seems cleaner like the opBinaryRight soluti

Re: Overriding "in" operator

2011-03-04 Thread spir
On 03/04/2011 05:01 PM, Magnus Lie Hetland wrote: I'm writing a collection with functionality for membership checking. I thought it would be nice to use the "in" operator. In the docs for std.collections I surmise that this is the standard way to go. From the source code, I

Re: Overriding "in" operator

2011-03-04 Thread Simen kjaeraas
Magnus Lie Hetland wrote: On 2011-03-04 17:06:29 +0100, Mafi said: If you try to use it in the manner of `something in classWhichDefinesThisOpBinary` then it doesn't work because operator overloading normally overloads on the left operand (ie something). Use opBinaryRight(string op)(...)

Re: Overriding "in" operator

2011-03-04 Thread Magnus Lie Hetland
On 2011-03-04 17:06:29 +0100, Mafi said: If you try to use it in the manner of `something in classWhichDefinesThisOpBinary` then it doesn't work because operator overloading normally overloads on the left operand (ie something). Use opBinaryRight(string op)(...) if(...) to get it working. Aa

Re: Overriding "in" operator

2011-03-04 Thread Mafi
Am 04.03.2011 17:01, schrieb Magnus Lie Hetland: I'm writing a collection with functionality for membership checking. I thought it would be nice to use the "in" operator. In the docs for std.collections I surmise that this is the standard way to go. From the source code, I see the

Overriding "in" operator

2011-03-04 Thread Magnus Lie Hetland
I'm writing a collection with functionality for membership checking. I thought it would be nice to use the "in" operator. In the docs for std.collections I surmise that this is the standard way to go. From the source code, I see there's no special opIn, but that it can be

Re: !in operator

2010-12-26 Thread Andrej Mitrovic
Works in D2, but not in D1. Perhaps this is only a D2 feature? On 12/26/10, Jacek Nowak wrote: > Hi, I don't know if it's the right place for this, I prefer forums to > newsgroups. Anyway, I am learning D and trying to work with associative > arrays. > > Code (I'm using v1.065 of the DMD compiler

Re: !in operator

2010-12-26 Thread bearophile
Jacek Nowak: > Hi, I don't know if it's the right place for this, I prefer forums to > newsgroups. This is the right place. And I think you need to get used to the newsgroups. There is also the IRC #D channel. > now, according to http://digitalmars.com/d/1.0/expression.html > "The !in express

!in operator

2010-12-26 Thread Jacek Nowak
Hi, I don't know if it's the right place for this, I prefer forums to newsgroups. Anyway, I am learning D and trying to work with associative arrays. Code (I'm using v1.065 of the DMD compiler): int[char[]] arr; if ("foo" in arr) { }; if ("foo" !in arr) // if (!("foo" in arr)) obvi