std::reverse_copy
来自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 BidirIt, class OutputIt > OutputIt reverse_copy( BidirIt first, BidirIt last, OutputIt d_first ); |
||
范围从
[first, last)
元素,到另一个范围内以这样的方式开始于d_first
,新的范围中的元素是在相反的顺序. Original:
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. 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 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_first | - | 的目标范围的开头
Original: the beginning of the destination range 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 .
| ||
-OutputIt must meet the requirements of OutputIterator .
|
[编辑] 返回值
输出迭代器复制过去的最后一个元素的元素
Original:
Output iterator to the element past 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.
[编辑] 可能的实现
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; }
Output:
1 2 3 3 2 1
[编辑] 复杂性
线性
first
和last
之间的距离Original:
linear in the distance between
first
and last
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.
[编辑] 另请参阅
在一定范围内的顺序颠倒元素 Original: reverses the order elements in a range The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数模板) |