◐ Shell
clean mode source ↗

std::move - 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 InputIt, class OutputIt > OutputIt move( InputIt first, InputIt last, OutputIt d_first );

(dal C++11)

Sposta gli elementi nel [first, last) gamma, ad un altro inizio gamma a d_first. Dopo questa operazione gli elementi della mosso-da posizione conterrà ancora valori validi del tipo appropriato, ma non necessariamente gli stessi valori di prima del trasloco.

Original:

Moves the elements in the range [first, last), to another range beginning at d_first. After this operation the elements in the moved-from range will still contain valid values of the appropriate type, but not necessarily the same values as before the move.

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 di elementi da spostare

Original:

the range of elements to move

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

d_first -

l'inizio del campo di destinazione. Se d_first è all'interno [first, last), std::move_backward deve essere usato al posto di NJ std :: mossa </ span> .

Original:

the beginning of the destination range. If d_first is within [first, last), std::move_backward must be used instead of NJ std :: mossa </ span>.

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

Type requirements
-InputIt must meet the requirements of InputIterator.
-OutputIt must meet the requirements of OutputIterator.

Valore di ritorno

Iteratore di uscita all'elemento passato l'ultimo elemento spostato (d_first + (last - first))

Original:

Output iterator to the element past the last element moved (d_first + (last - first))

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 spostare le assegnazioni.

Original:

Exactly last - first move 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 InputIt, class OutputIt>
OutputIt move(InputIt first, InputIt last, 
                    OutputIt d_first)
{
    while (first != last) {
        *d_first++ = std::move(*first++);
    }
    return d_first;
}

Esempio

Il codice seguente sposta oggetti thread (che a loro volta non sono copiabili) da un contenitore ad un altro. </ p>

Original:

The following code moves thread objects (which themselves are not copyable) from one container to another.

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

#include <iostream> #include <vector> #include <list> #include <iterator> #include <thread> #include <chrono> void f(int n) { std::this_thread::sleep_for(std::chrono::seconds(n)); std::cout << "thread " << n << " ended" << '\n'; } int main() { std::vector<std::thread> v; v.emplace_back(f, 1); v.emplace_back(f, 2); v.emplace_back(f, 3); std::list<std::thread> l; // copy() would not compile, because std::thread is noncopyable std :: mossa </ span>(v.begin(), v.end(), std::back_inserter(l)); for(auto& t : l) t.join(); }

Uscita:

Original:

Output:

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

thread 1 ended
thread 2 ended
thread 3 ended

Vedi anche

sposta un intervallo di elementi in una nuova posizione in ordine inverso

Original:

moves a range of elements to a new location in backwards order

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]