!in operator?
Jason House
jason.james.house at gmail.com
Sun May 24 12:18:14 PDT 2009
Stewart Gordon Wrote:
> Jason House wrote:
> <snip>
> > That is unfortunately a rather sticky point. The in operator does not
> > return bool. I think the lack of !in is to encourage writing of efficient
> > code. I'm not really sure though.
>
> How, exactly, does not having !in make code efficient?
>
> Stewart.
Consider the following code snippets:
Method 1:
if (x !in y)
foo();
else{
auto z = x in y;
bar(z);
}
Method 2:
auto z = x in y;
if (z is null)
foo;
else
bar(z);
Method 1 essentially calls in twice while method 2 calls in once.
PS: Please don't assume that I'm advocating not having a !in operator. I'm just pointing out possible reasons it may have been avoided.
More information about the Digitalmars-d
mailing list