Iterators for D

Bill Baxter dnewsgroup at billbaxter.com
Mon Nov 6 22:26:25 PST 2006


Sean Kelly wrote:
>>>
>>> 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.

Well, they could.  It's up to Mr. Compiler Writer if a pointer has a 
value property or not.

> 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.

Agreed.  I don't think I've ever actually used a raw pointer with a 
fancy STL algorithm.  I was actually really surprised the first time I 
saw it in the examples on the SGI STL page.  Other than those examples, 
I've never seen it in real code.

And that should go double for D, where you rarely even see pointers to 
begin with.

--bb



More information about the Digitalmars-d mailing list