Книга: Standard Template Library Programmer
rotate_copy
Разделы на этой странице:
rotate_copy
Category: algorithms
Component type: function
Prototype
template <class ForwardIterator, class OutputIterator>
OutputIterator rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
Description
Rotate_copy copies elements from the range [first, last) to the range [result, result + (last – first)) such that *middle is copied to *result, *(middle + 1) is copied to *(result + 1), and so on. Formally, for every integer n such that 0 <= n < last – first, rotate_copy performs the assignment *(result + (n + (last – middle)) % (last – first)) = *(first + n). Rotate_copy is similar to copy followed by rotate, but is more efficient. The return value is result + (last – first).
Definition
Defined in the standard header algorithm, and in the nonstandard backward-compatibility header algo.h.
Requirements on types
• ForwardIterator is a model of Forward Iterator.
• OutputIterator is a model of Output Iterator.
• ForwardIterator's value type is convertible to a type in OutputIterator's set of value types.
Preconditions
• [first, middle) is a valid range.
• [middle, last) is a valid range. [1]
• There is enough space to hold all of the elements being copied. More formally, the requirement is that [result, result + (last – first)) is a valid range.
• The ranges [first, last) and [result, result + (last – first)) do not overlap.
Complexity
Linear. Rotate_copy performs exactly last – first assignments.
Example
const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
rotate_copy(alpha, alpha + 13, alpha + 26, ostream_iterator<char>(cout));
// The output is nopqrstuvwxyzabcdefghijklm
Notes
[1] It follows from these two requirements that [first, last) is a valid range.
See also
rotate, copy.
- rotate
- 2. VERBATIM COPYING
- 3. COPYING IN QUANTITY
- 1. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
- copy_backward
- 12.5.7. logrotate
- Copying Files
- Copying Files Using tar
- Copying Files Using cp
- Using mc to Copy Files
- Using scp to Copy Individual Files Between Machines
- Using sftp to Copy Many Files Between Machines