Difference between revisions of "cpp/algorithm/rotate copy"
From cppreference.com
(clarified n_first parameter) |
m (Shorten template names. Use {{lc}} where appropriate.) |
||
Line 1: | Line 1: | ||
{{cpp/title|rotate_copy}} | {{cpp/title|rotate_copy}} | ||
{{cpp/algorithm/navbar}} | {{cpp/algorithm/navbar}} | ||
− | {{ | + | {{dcl begin}} |
− | {{ | + | {{dcl header | algorithm}} |
− | {{ | + | {{dcl | |
template< class ForwardIt, class OutputIt > | template< class ForwardIt, class OutputIt > | ||
OutputIt rotate_copy( ForwardIt first, ForwardIt n_first, | OutputIt rotate_copy( ForwardIt first, ForwardIt n_first, | ||
ForwardIt last, OutputIt d_first ); | ForwardIt last, OutputIt d_first ); | ||
}} | }} | ||
− | {{ | + | {{dcl end}} |
Copies the elements from the range {{tt|[first, last)}}, to another range beginning at {{tt|d_first}} in such a way, that the element {{tt|n_first}} becomes the first element of the new range and {{tt|n_first - 1}} becomes the last element. | Copies the elements from the range {{tt|[first, last)}}, to another range beginning at {{tt|d_first}} in such a way, that the element {{tt|n_first}} becomes the first element of the new range and {{tt|n_first - 1}} becomes the last element. | ||
===Parameters=== | ===Parameters=== | ||
− | {{ | + | {{par begin}} |
− | {{ | + | {{par | first, last | the range of elements to copy}} |
− | {{ | + | {{par | n_first | an iterator to an element in {{tt|[first, last)}} that should appear at the beginning of the new range}} |
− | {{ | + | {{par | d_first | beginning of the destination range}} |
− | {{ | + | {{par hreq}} |
− | {{ | + | {{par req concept | ForwardIt | ForwardIterator}} |
− | {{ | + | {{par req concept | OutputIt | OutputIterator}} |
− | {{ | + | {{par end}} |
===Return value=== | ===Return value=== | ||
Line 66: | Line 66: | ||
===See also=== | ===See also=== | ||
− | {{ | + | {{dsc begin}} |
− | {{ | + | {{dsc inc | cpp/algorithm/dcl list rotate}} |
− | {{ | + | {{dsc end}} |
[[de:cpp/algorithm/rotate copy]] | [[de:cpp/algorithm/rotate copy]] |
Revision as of 17:49, 31 May 2013
Defined in header <algorithm>
|
||
template< class ForwardIt, class OutputIt > OutputIt rotate_copy( ForwardIt first, ForwardIt n_first, |
||
Copies the elements from the range [first, last)
, to another range beginning at d_first
in such a way, that the element n_first
becomes the first element of the new range and n_first - 1
becomes the last element.
Contents |
Parameters
first, last | - | the range of elements to copy |
n_first | - | an iterator to an element in [first, last) that should appear at the beginning of the new range
|
d_first | - | beginning of the destination range |
Type requirements |
Return value
Output iterator to the element past the last element copied.
Possible implementation
Example
Run this code
#include <algorithm> #include <vector> #include <iostream> int main() { std::vector<int> src = {1, 2, 3, 4, 5}; auto pivot = std::find(src.begin(), src.end(), 3); std::vector<int> dest(src.size()); std::rotate_copy(src.begin(), pivot, src.end(), dest.begin()); for (const auto &i : dest) { std::cout << i << ' '; } std::cout << '\n'; }
Output:
3 4 5 1 2
Complexity
linear in the distance between first
and last