Associative array trouble
downs
default_357-line at yahoo.de
Fri Oct 16 20:04:22 PDT 2009
Bill Baxter wrote:
> You query presence of a key in an AA using 'in'
>
> if (id in symtab) {
> Symbol sym = symtab[id];
> ...
> } else {
> ..
> }
>
> Or this avoids a double lookup if the symbol is present:
>
> Symbol* pSym = id in symtab;
> if (pSym !is null) {
> Symbol sym = *pSym;
> ...
> } else {
> ...
> }
>
> --bb
>
Slightly shorter form:
if (auto pSym = id in symtab) { ... }
More information about the Digitalmars-d-learn
mailing list