Iterators for D

Sean Kelly sean at f4.ca
Mon Nov 6 22:02:03 PST 2006


Walter Bright wrote:
> Jarrett Billingsley wrote:
>> "Walter Bright" <newshound at digitalmars.com> wrote in message 
>> news:eio6u5$1j6o$1 at digitaldaemon.com...
>>
>>> Overload opIndex for rvalue access
>>> Overload opIndexAssign for lvalue access
>>
>> Somehow..
>>
>> foreach(i; foo)
>> {
>>     auto x = i[0];
>>     i[0] = x + 1;
>> }
>>
>> You often say that operator overloading should be used only what it 
>> should be used for, and taking the index of an iterator means.. what 
>> exactly?
>>
>> Would it be nicer to just use a .value property instead?
>>
>> foreach(i; foo)
>> {
>>     auto x = i.value;
>>     i.value = x + 1;
>> } 
> 
> The problem is if the iterator is an actual pointer, there is no .value 
> property for a pointer.

Is there really any reason to support pointers as iterators though?  C++ 
libraries even seem to be moving away from that towards more robust and 
less error-prone iterator objects.


Sean



More information about the Digitalmars-d mailing list