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++; } }