Bidirectional Example template void reverse(BI begin, BI end) { while ( (begin != end) && (begin != --end) ) { swap(*begin++, *end); } }