Iterators for D

Bill Baxter dnewsgroup at billbaxter.com
Mon Nov 6 23:06:34 PST 2006


Walter Bright wrote:
> Bill Baxter wrote:
>> Sean Kelly wrote:
>>>> The problem is if the iterator is an actual pointer, there is no 
>>>> .value property for a pointer.
>>
>> Well, they could.  It's up to Mr. Compiler Writer if a pointer has a 
>> value property or not.
> 
> Consider the following struct:
> 
>     struct Foo
>     {
>         int value;
>     }
> 
> Foo* p;
> 
> p.value;
> 
> Is p.value the entire contents of Foo (as it would be for a proposed 
> .value property) or just Foo.value? "value" is a pretty common field name.

It's a name conflict.  They happen.  I'd have trouble if I wanted to 
have a sizeof member in my struct too.  If you want to be sure to get 
the struct's member then use p[0].value.

'Value' is too common, though.  If you were going to go that route it 
should definitely be something like .iterVal or some other word less 
likely to conflict.

I'm not saying it's the right way to go, just that it could be made to 
work if needed.

--bb



More information about the Digitalmars-d mailing list