function template
<algorithm>
std::reverse
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
noneExample
|
|
Output:
myvector contains: 9 8 7 6 5 4 3 2 1
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.
See also
- reverse_copy
- Copy range reversed (function template)
- rotate
- Rotate left the elements in range (function template)
- random_shuffle
- Randomly rearrange elements in range (function template)
- swap
- Exchange values of two objects (function template)