www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - !in operator

reply Jacek Nowak <jaceknowak wp.eu> writes:
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)) obviously works
{
};


unfortunately, only the first "if" statement works, while the second one gives
compiler errors:

hello.d|72|found '!' when expecting ')'|
hello.d|72|found 'in' instead of statement|

now, according to http://digitalmars.com/d/1.0/expression.html

"The !in expression is the logical negation of the in operation."

is it a known bug or am I misunderstanding something?
Dec 26 2010
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
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 expression is the logical negation of the in operation."
 is it a known bug or am I misunderstanding something?
Isn't the !in present in D2 only? (If this is right, then that's a documentation bug that needs to be reported). Bye, bearophile
Dec 26 2010
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Works in D2, but not in D1. Perhaps this is only a D2 feature?

On 12/26/10, Jacek Nowak <jaceknowak wp.eu> 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):

 int[char[]] arr;

 if ("foo" in arr)
 {
 };

 if ("foo" !in arr)              // if (!("foo" in arr)) obviously works
 {
 };


 unfortunately, only the first "if" statement works, while the second one
 gives
 compiler errors:

 hello.d|72|found '!' when expecting ')'|
 hello.d|72|found 'in' instead of statement|

 now, according to http://digitalmars.com/d/1.0/expression.html

 "The !in expression is the logical negation of the in operation."

 is it a known bug or am I misunderstanding something?
Dec 26 2010