std::reverse_copy
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    |  | 该页由英文版wiki使用Google Translate机器翻译而来。 
 该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. | 
| 在头文件 <algorithm> 中定义
  | ||
| template< class BidirIt, class OutputIt > OutputIt reverse_copy( BidirIt first, BidirIt last, OutputIt d_first ); | ||
范围从
[first, last)元素,到另一个范围内以这样的方式开始于d_first,新的范围中的元素是在相反的顺序. 原文:
Copies the elements from the range 
[first, last), to another range beginning at d_first in such a way, that the elements in the new range are in reverse order. | 目录 | 
[编辑] 参数
| first, last | - |  元素的范围内,要复制的复本 | 
| d_first | - |  的目标范围的开头 原文:  the beginning of the destination range | 
| 类型要求 | ||
| - BidirIt必须满足BidirectionalIterator的要求。 | ||
| - OutputIt必须满足OutputIterator的要求。 | ||
[编辑] 返回值
输出迭代器复制过去的最后一个元素的元素
原文:
Output iterator to the element past the last element copied.
[编辑] 可能的实现
| template<class BidirIt, class OutputIt> OutputIt reverse_copy(BidirIt first, BidirIt last, OutputIt d_first) { while (first != last) { *(d_first++) = *(--last); } return d_first; } | 
[编辑] 为例
#include <vector> #include <iostream> #include <algorithm> int main() { std::vector<int> v({1,2,3}); std::for_each(std::begin(v), std::end(v), [&](int value){ std::cout << value << " "; }); std::cout << std::endl; std::vector<int> destiny(3); std::reverse_copy(std::begin(v), std::end(v), std::begin(destiny)); std::for_each(std::begin(destiny), std::end(destiny), [&](int value){ std::cout << value << " "; }); std::cout << std::endl; }
输出:
1 2 3 3 2 1
[编辑] 复杂性
线性
first和last之间的距离原文:
linear in the distance between 
first and last[编辑] 另请参阅
| 将区间内的元素颠倒顺序 (函数模板) | |


