1) Reverses the order of the elements in the range [
first,
last)
.
Behaves as if applying
ranges::iter_swapto every pair of iterators
first + i, last - i - 1for each integer
i
, where
0 ⤠i < (last - first) / 2.
The function-like entities described on this page are algorithm function objects (informally known as niebloids), that is:
An iterator equal to last.
[edit] ComplexityExactly (last - first) / 2 swaps.
[edit] NotesImplementations (e.g. MSVC STL) may enable vectorization when the iterator type models contiguous_iterator
and swapping its value type calls neither non-trivial special member function nor ADL-found swap
.
See also implementations in libstdc++ and MSVC STL.
[edit] Example#include <algorithm> #include <array> #include <iostream> #include <string> int main() { std::string s {"ABCDEF"}; std::cout << s << " â "; std::ranges::reverse(s.begin(), s.end()); std::cout << s << " â "; std::ranges::reverse(s); std::cout << s << " â "; std::array a {1, 2, 3, 4, 5}; for (auto e : a) std::cout << e << ' '; std::cout << "â "; std::ranges::reverse(a); for (auto e : a) std::cout << e << ' '; std::cout << '\n'; }
Output:
ABCDEF â FEDCBA â ABCDEF â 1 2 3 4 5 â 5 4 3 2 1[edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4