std::reverse
提供: cppreference.com
![]() | このページは、Google 翻訳を使って英語版から機械翻訳されました。 翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
ヘッダ <algorithm> で定義 | ||
template<class BidirIt > void reverse( BidirIt first, BidirIt last ); | ||
レンジ
[first, last)
の要素の順序を反転.Original:
Reverses the order of the elements in the range
[first, 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.
目次 |
[編集]パラメータ
first, last | - | 逆転する要素の範囲 Original: the range of elements to reverse The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
型の要件 | ||
-BidirIt は BidirectionalIterator の要件を満たさなければなりません。 | ||
-The type of dereferenced BidirIt must meet the requirements of Swappable . |
[編集]値を返します
(なし)
[編集]可能な実装
template<class BidirIt>void reverse(BidirIt first, BidirIt last){while((first != last)&&(first !=--last)){std::swap(*first++, *last);}} |
[編集]例
Run this code
#include <vector>#include <iostream>#include <algorithm> int main(int argc, char** argv){std::vector<int> v({1,2,3}); std::reverse(std::begin(v), std::end(v));std::cout<< v[0]<< v[1]<< v[2]<<'\n'; int a[]={4, 5, 6, 7}; std::reverse(&a[0], &a[4]);std::cout<< a[0]<< a[1]<< a[2]<< a[3]<<'\n';}
出力:
321 7654
[編集]複雑性
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.
[編集]参照
指定範囲の要素の順序を反転させたコピーを作成します (関数テンプレート) |