std::reverse_copy
De cppreference.com
[] |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody>| Dclar dans l'en-tte <algorithm>
|
||
template< class BidirIt, class OutputIt > OutputIt reverse_copy( BidirIt first, BidirIt last, OutputIt d_first ); |
||
Copie les lments de la gamme
[first, last), une autre gamme dbutant d_first de telle sorte que les lments de la nouvelle gamme sont en .. l'ordre inverse . 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.
Paramtres
| first, last | - | l'ventail des lments copier
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 | - | le dbut de la plage de destination
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. |
| Type requirements | ||
-BidirIt must meet the requirements of BidirectionalIterator.
| ||
-OutputIt must meet the requirements of OutputIterator.
| ||
Retourne la valeur
sortie itrateur l'lment aprs le dernier lment copi .
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.
Mise en uvre possible
template<class BidirIt, class OutputIt>
OutputIt reverse_copy(BidirIt first, BidirIt last, OutputIt d_first)
{
while (first != last) {
*(d_first++) = *(--last);
}
return d_first;
}
|
Exemple
#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;
}
Rsultat :
1 2 3
3 2 1
Complexit
linaire de la distance entre
first et lastOriginal:
linear in the distance between
first and lastThe 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.
Voir aussi
inverse les lments de commande dans une gamme Original: reverses the order elements in a range The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction gnrique) | |