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

std::swap_ranges

提供: cppreference.com
< cpp‎ | algorithm

 
 
アルゴリズムライブラリ
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を非改変
Original:
Non-modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を変更する
Original:
Modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
操作を仕切る
Original:
Partitioning operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(ソートされた範囲で)ソート操作
Original:
Sorting operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
バイナリ検索操作(ソート範囲で)
Original:
Binary search operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(ソートされた範囲で)操作を設定します
Original:
Set operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ヒープ操作
Original:
Heap operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
最小値/最大値操作
Original:
Minimum/maximum operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
数値演算
Original:
Numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cライブラリ
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Defined in header <algorithm>
template<class ForwardIt1, class ForwardIt2 >
ForwardIt2 swap_ranges( ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2 )
レンジ[first1, last1)first2から始まる別の範囲の間の交流の要素.
Original:
Exchanges elements between range [first1, last1) and another range starting at first2.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集]パラメータ

first1, last1 -
スワップする要素の最初の範囲
Original:
the first range of elements to swap
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
first2 -
スワップする要素の第2の範囲の始まり
Original:
beginning of the second range of elements to swap
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
型の要件
-
ForwardIt1, ForwardIt2ForwardIterator

の要求を満足しなければなりません。

-
The types of dereferenced ForwardIt1 and ForwardIt2 must meet the requirements of Swappable

[編集]値を返します

first2始まる範囲で交換最後の要素の要素を指すイテレータ.
Original:
Iterator to the element past the last element exchanged in the range beginning with first2.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]可能な実装

template<class ForwardIt1, class ForwardIt2> ForwardIt1 swap_ranges(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2){while(first1 != last1){std::iter_swap(first1++, first2++);}return first2;}

[編集]

別の容器からの部分的な範囲のスワッピングを示しています
Original:
Demonstrates swapping of subranges from different containers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <algorithm>#include <list>#include <vector>#include <iostream>int main(){std::vector<int> v ={1, 2, 3, 4, 5};std::list<int> l ={-1, -2, -3, -4, -5};   std::swap_ranges(v.begin(), v.begin()+3, l.begin());   for(int n : v)std::cout<< n <<' ';std::cout<<'\n';for(int n : l)std::cout<< n <<' ';std::cout<<'\n';}

出力:

-1 -2 -3 4 5 1 2 3 -4 -5

[編集]複雑性

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.

[編集]参照

スワップ二つのイテレータが指す要素
Original:
swaps the elements pointed to by two iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート)[edit]
2つのオブジェクトの値を交換します
(関数テンプレート)[edit]
close