std::reverse_copy
De cppreference.com
![]() |
Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate.
La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí. |
Definido en el archivo de encabezado <algorithm>
|
||
template< class BidirIt, class OutputIt > OutputIt reverse_copy( BidirIt first, BidirIt last, OutputIt d_first ); |
||
Copia los elementos de la
[first, last)
rango, a otro principio rango en d_first
de tal manera, que los elementos de la nueva gama son en .. orden inverso . Original:
Copies the elements from the range
[first, last)
, to another range beginning at d_first
in such a way, that the elements in the new range are in reverse order. 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.
Contenido |
[editar] Parámetros
first, last | - | la gama de elementos a copiar
Original: the range of elements to copy The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
d_first | - | el comienzo del rango de destino
Original: the beginning of the destination range The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Requisitos de tipo | ||
-BidirIt debe reunir los requerimientos de BidirectionalIterator .
| ||
-OutputIt debe reunir los requerimientos de OutputIterator .
|
[editar] Valor de retorno
salida iterador al elemento más allá del último elemento copiado .
Original:
Output iterator to the element past the last element copied.
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.
[editar] Posible implementación
template<class BidirIt, class OutputIt> OutputIt reverse_copy(BidirIt first, BidirIt last, OutputIt d_first) { while (first != last) { *(d_first++) = *(--last); } return d_first; } |
[editar] Ejemplo
Ejecuta este código
#include <vector> #include <iostream> #include <algorithm> int main() { std::vector<int> v({1,2,3}); std::for_each(std::begin(v), std::end(v), [&](int value){ std::cout << value << " "; }); std::cout << std::endl; std::vector<int> destiny(3); std::reverse_copy(std::begin(v), std::end(v), std::begin(destiny)); std::for_each(std::begin(destiny), std::end(destiny), [&](int value){ std::cout << value << " "; }); std::cout << std::endl; }
Salida:
1 2 3 3 2 1
[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.
You can help to correct and verify the translation. Click here for instructions.
[editar] Ver también
Invierte el orden de los elementos en un rango. (plantilla de función) |