My Kingdom For ...
Christopher Wright
dhasenan at gmail.com
Thu Feb 21 19:17:06 PST 2008
Ary Borenszweig wrote:
> 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
> }
That would be better if the language allowed:
// value not defined
if (aa.TryGetValue(key, out object value))
{
// ok, now I can use value
}
else
{
// Key not found
}
More information about the Digitalmars-d
mailing list