Espacios de nombres
Variantes
Acciones

std::swap_ranges

De cppreference.com
< cpp‎ | algorithm
 
 
Biblioteca de algoritmos
Políticas de ejecución (C++17)
Operaciones no modificadoras de secuencia
(C++11)(C++11)(C++11)
(C++17)
Operaciones modificadoras de secuencia
Operaciones en almacenamiento no inicializado
Operaciones de partición
Operaciones de ordenación
(C++11)
Operaciones de búsqueda binaria
Operaciones de set (en rangos ordenados)
Operaciones de pila
(C++11)
Operaciones minimo/maximo
(C++11)
(C++17)
Permutaciones
Operaciones numéricas
Bibliotecas C
 
Definido en la cabecera <algorithm>
template< class ForwardIt1, class ForwardIt2 >
ForwardIt2 swap_ranges( ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2 )
Intercambios entre elementos [first1, last1) gama y otro rango que comienza en 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.

Contenido

[editar] Parámetros

first1, last1 -
la primera gama de elementos a intercambiar
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 -
a partir de la segunda gama de elementos para intercambiar
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.
Requerimientos de tipo
-
ForwardIt1, ForwardIt2 debe reunir los requerimientos de ForwardIterator.
-
The types of dereferenced ForwardIt1 and ForwardIt2 must meet the requirements of Swappable

[editar] Valor de retorno

Iterator al elemento pasado el último elemento intercambió al principio gama con 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] Posible implementación

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] Ejemplo

Muestra el intercambio de los subintervalos de diferentes contenedores
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';
}

Salida:

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

[editar] Complejidad

lineal en la distancia entre first y 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] Ver también

intercambia los elementos apuntado por dos 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.

(plantilla de función) [editar]
intercambia los valores de dos 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.

(plantilla de función) [editar]