◐ Shell
clean mode source ↗

std::copy_backward - cppreference.com

Da cppreference.com.

Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.

La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui.

Click here for the English version of this page

<metanoindex/>

<tbody> </tbody>

Elemento definito nell'header

<algorithm>

template< class BidirIt1, class BidirIt2 > BidirIt2 copy_backward( BidirIt1 first, BidirIt1 last, BidirIt2 d_last );

Copia gli elementi della gamma, definito da [first, last), ad un altro intervallo termina a d_last. Gli elementi vengono copiati in ordine inverso (l'ultimo elemento viene copiato prima), ma il loro ordine relativo è conservato.

Original:

Copies the elements from the range, defined by [first, last), to another range ending at d_last. The elements are copied in reverse order (the last element is copied first), but their relative order is preserved.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Parametri

first, last -

la gamma degli elementi da copiare

Original:

the range of the 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_last -

fine del campo di destinazione. Se d_last è all'interno [first, last), std::copy deve essere usato al posto di std::copy_backward .

Original:

end of the destination range. If d_last is within [first, last), std::copy must be used instead of std::copy_backward.

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.

Valore di ritorno

iteratore per l'ultimo elemento copiato.

Original:

iterator to 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.

Complessità

Esattamente last - first incarichi.

Original:

Exactly last - first assignments.

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Possibile implementazione

template< class BidirIt1, class BidirIt2 >
BidirIt2 copy_backward(BidirIt1 first, BidirIt1 last, BidirIt2 d_last)
{
    while (first != last) {
        *(--d_last) = *(--last);
    }
    return d_last;
}

Esempio

#include <algorithm>
#include <iostream>
 
int main()
{
    std::vector<int> from_vector;
    for (int i = 0; i < 10; i++) {
        from_vector.push_back(i);
    }
 
    std::vector<int> to_vector(15);
 
    std::copy_backward(from_vector.begin(), from_vector.end(), to_vector.end());
 
    std::cout << "to_vector contains: ";
    for (unsigned int i = 0; i < to_vector.size(); i++) {
        std::cout << to_vector[i] << " ";
    }
 }

Output:

to_vector contains: 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9

Vedi anche

copia un intervallo di elementi in una nuova posizione

Original:

copies a range of elements to a new location

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.


(funzione di modello) [modifica]