template <class BidirectionalIterator>
void reverse (BidirectionalIterator first, BidirectionalIterator last);
Reverse range
[first,last)
.The function calls iter_swap to swap the elements to their new locations.
The behavior of this function template is equivalent to:
|
|
Parameters
- first, last
- Bidirectional iterators to the initial and final positions of the sequence to be reversed. The range used is
[first,last)
, which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
BidirectionalIterator shall point to a type for which swap is properly defined.
Return value
none
Example
|
|
Output:
|
Complexity
Linear in half the distance between first and last: Swaps elements.
Data races
The objects in the range[first,last)
are modified.
Exceptions
Throws if either an element swap or an operation on an iterator throws.Note that invalid arguments cause undefined behavior.