As promised in today's lecture, here are the rewrites of the hard-to-read
code examples from the Bidirectional Iterator section of today's lecture.
Hopefully these are easier to understand, though you might find drawing
pictures of arrays/vectors make understanding how they work easier.
template <typename BI, typename OI>
OI reverse_copy(BI begin, BI end, OI out) {
while (begin != end) {
end--;
*out = *end;
out++;
}
return out;
}
template <typename BI>
void reverse(BI begin, BI end) {
while (true) {
if (begin == end) break;
end--;
if (begin == end) break;
swap(*begin, *end);
begin++;
}
}