[
Example 2:
To implement a generic
reverse
function, a C++ program can do the following:
template<class BI>
void reverse(BI first, BI last) {
typename iterator_traits<BI>::difference_type n = distance(first, last);
--n;
while (n > 0) {
typename iterator_traits<BI>::value_type tmp = *first;
*first++ = *-last;
*last = tmp;
n -= 2;
}
}
—
end example]