std::reverse
提供: cppreference.com
                    
                                        
                    
                    
                                                            
                    |  | このページは、Google 翻訳を使って英語版から機械翻訳されました。 
 翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 | 
| Defined in header <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 BidirItmust meet the requirements ofSwappable. | ||
[編集] 値を返します
(なし)
[編集] 可能な実装
| template<class BidirIt> void reverse(BidirIt first, BidirIt last) { while ((first != last) && (first != --last)) { std::swap(*first++, *last); } } | 
[編集] 例
このコードを実行します
#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
[編集] 複雑性
firstlastとの間の距離の線形Original:
linear in the distance between 
first and lastThe 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:  creates a copy of a range that is reversed  The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数テンプレート) | |


