On Fri, Aug 3, 2012 at 2:04 PM, Jakob Stoklund Olesen <span dir="ltr"><<a href="mailto:stoklund@2pi.dk" target="_blank" class="cremed">stoklund@2pi.dk</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
On Aug 3, 2012, at 1:11 PM, Chandler Carruth <<a href="mailto:chandlerc@gmail.com" class="cremed">chandlerc@gmail.com</a>> wrote:<br>
<br>
> The gist of it is this:<br>
><br>
> Imagine you have a sorted vector, and are processing each element. One step of the processing has the option of producing new values that should be inserted into the vector. Because they are already processed, they don't need to be visited again, and so you simple push_back everything new, and sort the vector again at the end.<br>

<br>
</div>But how is this iterator abstraction an improvement over 'unsigned'?<br></blockquote><div><br></div><div>Well, in a sense, it isn't really improving the abstraction, it's mostly improving the syntax: </div>
<div><br></div><div>I can write "I->foo()" to access a member rather than "MyContainerVariable[i].foo()".</div><div><br></div><div>I don't have to pass the container to a static helper function.</div>
<div><br></div><div>I can call 'sort' on it and any other standard algorithms.</div><div><br></div><div>I can change code from the normal iterator to the indexed iterator without rewriting if/when the invalidation problem arises. Only a type change is required.</div>
<div><br></div><div><br></div><div>So is it necessary or more powerful than 'unsigned'? Certainly not. But I find it extremely convenient, and it made my code significantly more readable to use it. It allows me to write more code uniformly with iterators rather than mixing iterator patterns and index patterns.</div>
</div></div>