Call signature
(1) (since C++20) (2) (since C++20)Helper types
(3) (since C++20) 1)Copies the elements from the source range
[
first,
last)
to the destination range
[
result,
result + N)
, where
N
is
ranges::distance(first, last), in such a way that the elements in the new range are in reverse order. Behaves as if by executing the assignment
*(result + N - 1 - i) = *(first + i)once for each integer
i
in
[
â0â,
N)
. The behavior is undefined if the source and destination ranges overlap.
The function-like entities described on this page are algorithm function objects (informally known as niebloids), that is:
{last, result + N}.
[edit] ComplexityExactly N
assignments.
Implementations (e.g. MSVC STL) may enable vectorization when the both iterator types model contiguous_iterator
and have the same value type, and the value type is TriviallyCopyable.
See also the implementations in MSVC STL and libstdc++.
struct reverse_copy_fn { template<std::bidirectional_iterator I, std::sentinel_for<I> S, std::weakly_incrementable O> requires std::indirectly_copyable<I, O> constexpr ranges::reverse_copy_result<I, O> operator()(I first, S last, O result) const { auto ret = ranges::next(first, last); for (; last != first; *result = *--last, ++result); return {std::move(ret), std::move(result)}; } template<ranges::bidirectional_range R, std::weakly_incrementable O> requires std::indirectly_copyable<ranges::iterator_t<R>, O> constexpr ranges::reverse_copy_result<ranges::borrowed_iterator_t<R>, O> operator()(R&& r, O result) const { return (*this)(ranges::begin(r), ranges::end(r), std::move(result)); } }; inline constexpr reverse_copy_fn reverse_copy {};[edit] Example
#include <algorithm> #include <iostream> #include <string> int main() { std::string x {"12345"}, y(x.size(), ' '); std::cout << x << " â "; std::ranges::reverse_copy(x.begin(), x.end(), y.begin()); std::cout << y << " â "; std::ranges::reverse_copy(y, x.begin()); std::cout << x << '\n'; }
Output:
12345 â 54321 â 12345[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