!in operator?
Stewart Gordon
smjg_1998 at yahoo.com
Sun May 24 15:05:53 PDT 2009
Jason House wrote:
<snip>
> 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.
<snip>
But there's no requirement to look it up after finding out whether it's
there or not.
And how's it any different from
if (x in y) {
auto z = x in y;
bar(z);
} else {
foo();
}
or even
if (x in y) {
bar(y[x]);
} else {
foo();
}
?
Besides, why would any decent compiler not optimise it to a single lookup?
Stewart.
More information about the Digitalmars-d
mailing list