std::reverse_copy - cppreference.com
De cppreference.com
<metanoindex/>
<tbody> </tbody>
| Definido no cabeçalho <algorithm> |
||
|
|
||
copia os elementos do [first, last) gama, a outra faixa no início d_first de tal forma, que os elementos da nova gama estão em.. ordem inversa.
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.
Parâmetros
| first, last | - | a gama de elementos para copiar Original: the range of elements to copy The text has been machine-translated via Google Translate. |
| d_first | - | o início do intervalo de destino Original: the beginning of the destination range The text has been machine-translated via Google Translate. |
| Type requirements | ||
-BidirIt must meet the requirements of BidirectionalIterator.
| ||
-OutputIt must meet the requirements of OutputIterator.
| ||
Valor de retorno
iterador de saída para o elemento passado o ú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.
Possível implementação
template<class BidirIt, class OutputIt> OutputIt reverse_copy(BidirIt first, BidirIt last, OutputIt d_first) { while (first != last) { *(d_first++) = *(--last); } return d_first; }
Exemplo
#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; }
Saída:
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.
Veja também
inverte os elementos de ordem em um intervalo Original: reverses the order elements in a range The text has been machine-translated via Google Translate. (modelo de função) [edit] | |