Iterating over containers of immutable objects
Steven Schveighoffer
schveiguy at yahoo.com
Thu Jul 1 04:13:05 PDT 2010
On Tue, 29 Jun 2010 19:08:13 -0400, Justin Johansson <no at spam.com> wrote:
> Steven Schveighoffer wrote:
>> On Tue, 29 Jun 2010 18:42:18 -0400, Justin Johansson <no at spam.com>
>> wrote:
>>
>>> Steven Schveighoffer wrote:
>>
>>> There is another solution which requires introducing an extra virtual
>>> method (and associated cost thereof) namely "hasNext" to the iterator
>>> interface. This allows pulling a single item (if it exists) out of
>>> the iterator on demand.
>> Duh... I just thought of this too:
>> while(auto bar = iter.next()) // line 37
>> {
>> ...
>> }
>
> Sorry that does not compile, dunno if it should I'm using
> the latest D2.
>
> test.d(37): expression expected, not 'auto'
> test.d(37): found 'bar' when expecting ')'
> test.d(37): found '=' instead of statement
> test.d(41): unrecognized declaration
Hm... a common idiom to deal with whether an object casts to a type is
this:
if(auto c = cast(C)obj)
{
// use c
}
I wonder why while doesn't work...
Walter?
-Steve
More information about the Digitalmars-d
mailing list