std::copy_backward
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    |  | 该页由英文版wiki使用Google Translate机器翻译而来。 
 该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. | 
| 定义于头文件  <algorithm> | ||
| template< class BidirIt1, class BidirIt2 > BidirIt2 copy_backward( BidirIt1 first, BidirIt1 last, BidirIt2 d_last ); | ||
复制的元素的范围,定义的
[first, last),另一个范围在d_last结束。以相反的顺序(第一个被复制的最后一个元素)的元素复制,但它们的相对顺序是保留的.原文:
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.| 目录 | 
[编辑] 参数
| first, last | - |  的范围内的元素进行复制 | 
| d_last | - |  年底的目标范围内。如果 d_last内[first, last),std::copy必须使用代替std::copy_backward.原文:  end of the destination range. If  d_lastis within[first, last), std::copy must be used instead of std::copy_backward. | 
| 类型要求 | ||
| - BidirIt必须满足 BidirectionalIterator的要求。 | ||
[编辑] 返回值
复制的最后一个元素的迭代器.
[编辑] 复杂度
究竟
last - first分配.[编辑] 可能的实现
| 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] << " "; } }
输出:
to_vector contains: 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9
[编辑] 另请参阅
| (C++11) | 将某一范围的元素复制到一个新的位置 (函数模板) | 


