Iterators for D
Sean Kelly
sean at f4.ca
Tue Nov 7 05:46:02 PST 2006
Bill Baxter wrote:
> 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.
I've used it a few times, but generally more when I'm throwing together
a quick test than writing actual production code. But since D arrays
aren't the same as C++ arrays and we have the option of getting a robust
object back (via a.begin() or whatever), why not take it?
Sean
More information about the Digitalmars-d
mailing list