The Wayback Machine - https://web.archive.org/web/20180317041459/http://ja.cppreference.com:80/w/cpp/algorithm/reverse_copy
名前空間
変種
操作

std::reverse_copy

提供: cppreference.com
< cpp‎ | algorithm

 
 
アルゴリズムライブラリ
実行ポリシー (C++17)
非変更シーケンス操作
(C++11)(C++11)(C++11)
(C++17)
変更シーケンス操作
未初期化記憶域の操作
分割操作
ソート操作
バイナリサーチ操作
集合操作 (ソート済み範囲に対する)
ヒープ操作
(C++11)
最小/最大演算
(C++11)
(C++17)
順列
数値演算
C のライブラリ
 
ヘッダ <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.

目次

[編集]パラメータ

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.
型の要件
-
BidirItBidirectionalIterator の要件を満たさなければなりません。
-
OutputItOutputIterator の要件を満たさなければなりません。

[編集]値を返します

出力イテレータ.
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.

[編集]可能な実装

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

[編集]複雑性

firstlastとの間の距離の線形
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.

[編集]参照

指定範囲の要素の順序を反転させます
(関数テンプレート)[edit]
close