std::copy_backward
来自cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Defined in header <algorithm>
|
||
template< class BidirIt1, class BidirIt2 > BidirIt2 copy_backward( BidirIt1 first, BidirIt1 last, BidirIt2 d_last ); |
||
复制的元素的范围,定义的
[first, last)
,另一个范围在d_last
结束。以相反的顺序(第一个被复制的最后一个元素)的元素复制,但它们的相对顺序是保留的.Original:
Copies the elements from the range, defined by
[first, last)
, to another range ending at d_last
. The elements are copied in reverse order (the last element is copied first), but their relative order is preserved.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
first, last | - | 的范围内的元素进行复制
Original: the range of the elements to copy The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
d_last | - | 年底的目标范围内。如果
d_last 内[first, last) ,std::copy必须使用代替std::copy_backward. Original: end of the destination range. If d_last is within [first, last) , std::copy must be used instead of std::copy_backward. The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Type requirements | ||
-BidirIt must meet the requirements of BidirectionalIterator .
|
[编辑] 返回值
复制的最后一个元素的迭代器.
Original:
iterator to the last element copied.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 复杂性
究竟
last - first
分配.Original:
Exactly
last - first
assignments.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 可能的实现
template< class BidirIt1, class BidirIt2 > BidirIt2 copy_backward(BidirIt1 first, BidirIt1 last, BidirIt2 d_last) { while (first != last) { *(--d_last) = *(--last); } return d_last; } |
[编辑] 为例
#include <algorithm> #include <iostream> int main() { std::vector<int> from_vector; for (int i = 0; i < 10; i++) { from_vector.push_back(i); } std::vector<int> to_vector(15); std::copy_backward(from_vector.begin(), from_vector.end(), to_vector.end()); std::cout << "to_vector contains: "; for (unsigned int i = 0; i < to_vector.size(); i++) { std::cout << to_vector[i] << " "; } }
Output:
to_vector contains: 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9
[编辑] 另请参阅
(C++11) |
某一范围的元素复制到一个新的位置 Original: copies a range of elements to a new location The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数模板) |