The Wayback Machine - https://web.archive.org/web/20180618075818/http://pt.cppreference.com:80/w/cpp/algorithm/swap_ranges
Espaços nominais
Variantes
Acções

std::swap_ranges

Da cppreference.com
< cpp‎ | algorithm

 
 
Biblioteca algoritmo
Funções
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Não modificar operações de seqüência
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.
Modificando operações de seqüência
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.
Particionamento operações
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.
Operações de classificação (em intervalos ordenados)
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.
Binários operações de busca (em intervalos ordenados)
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.
Definir operações (em intervalos ordenados)
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.
Operações de pilha
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.
Mínimo / máximo de operações
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.
Operações numéricas
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 biblioteca
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 )
Trocas elementos entre [first1, last1) gama e uma outra gama a partir de 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.

Índice

[editar]Parâmetros

first1, last1 -
a primeira gama de elementos para trocar
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 -
início da segunda gama de elementos para trocar
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.
Type requirements
-
ForwardIt1, ForwardIt2 must meet the requirements of ForwardIterator.
-
The types of dereferenced ForwardIt1 and ForwardIt2 must meet the requirements of Swappable

[editar]Valor de retorno

Iterador para o elemento passado o último elemento trocado no início gama com 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.

[editar]Possível implementação

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

[editar]Exemplo

Demonstra troca de subfaixas de diferentes recipientes
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';}

Output:

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

[editar]Complexidade

linear, em que a distância entre first e 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.

[editar]Veja também

troca os elementos apontado por dois iteradores
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.

(modelo de função)[edit]
troca os valores dos dois objetos
Original:
swaps the values of two objects
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(modelo de função)[edit]
close