My Kingdom For ...
Ary Borenszweig
ary at esperanto.org.ar
Thu Feb 21 07:40:19 PST 2008
Janice Caron escribió:
> 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!
I think the best solution is the one in .Net:
object value;
if (aa.TryGetValue(key, out value)) {
// Key found, value may be null
} else {
// Key not found
}
More information about the Digitalmars-d
mailing list