<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Feb 16, 2013 at 6:40 PM, Jakob Stoklund Olesen <span dir="ltr"><<a href="mailto:stoklund@2pi.dk" target="_blank" class="cremed">stoklund@2pi.dk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">>> I think it is too confusing to use reverse_iterators in an API. Can't you keep that detail internal to the function? Better yet, just use -- to move backwards.<br>

><br>
> I originally wrote it that way, but it felt awkward since we are iterating backwards over an interval (A, B] not forward over an interval [A, B). I guess you are just suggesting that I do the conversion from left-open to right-open intervals in the function itself.<br>

<br>
</div>Yes, but even then I usually just use:<br>
<br>
for (iterator I = End; I != Begin;) {<br>
  --I;<br>
  use(I);<br>
}<br></blockquote><div><br></div><div style>This prevents ever using an algorithm on the range, or (eventually) range-based for loops. I think that is the primary benefit of writing the above in terms of reverse iterators. It confused me the first time I saw it, but now I find the reverse iterator pattern quite friendly.</div>
<div style><br></div><div style>We could also help it by providing:</div><div style><br></div><div style>iterator RBegin, REnd;</div><div style>tie(RBegin, REnd) = reverse_iterator_pair(Begin, End);</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
It's less confusing IMHO.<br>
<br>
Note that dereferencing a MachineBasicBlock::reverse_iterator causes it to scan the whole bundle it is pointing to:<br>
<br>
  reference operator*() const {__t = current; return *--__t;}</blockquote></div><br>Regardless of the above, this seems bad. Couldn't this be factored into the increment step (much as I assume the decrement step in forward iterators does?)</div>
</div>