My Kingdom For ...

Leandro Lucarella llucax at gmail.com
Thu Feb 21 08:46:39 PST 2008


Janice Caron, el 21 de febrero a las 15:38 me escribiste:
> On 21/02/2008, Michiel Helvensteijn <nomail at please.com> wrote:
> > It's silly that 'in' does not return a bool.
> 
> Huh? But I don't want it to return a bool. If it retured a bool, I
> wouldn't be able to do
> 
>     auto p = key in aa;
>     if (p is null)
>     {
>         /* do something */
>     }
>     else
>     {
>         return *p;
>     }
> 
> Without that ability, you'd have to do a double-lookup!

What about the Python-way:

     auto p = aa.get(key);
     if (p is null)
     {
         /* do something */
     }
     else
     {
         return *p;
     }

And leave in as a bool operator?
get could take an optional parameter which is the value you want it to
return if the key is not present.

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
PROTESTA EN PLAZA DE MAYO: MUSICO SE COSIO LA BOCA
	-- Crónica TV



More information about the Digitalmars-d mailing list