std::move
![]() | 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. |
Defined in header <algorithm> | ||
template<class InputIt, class OutputIt > OutputIt move( InputIt first, InputIt last, OutputIt d_first ); | (dal C++11) | |
[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.[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.You can help to correct and verify the translation. Click here for instructions.
Indice |
[modifica]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>. </div>The text has been machine-translated via Google Translate. </div></div></div></div> 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 . |
[modifica]Valore di ritorno
You can help to correct and verify the translation. Click here for instructions.
[modifica]Complessità
last - first
spostare le assegnazioni.last - first
move assignments.You can help to correct and verify the translation. Click here for instructions.
[modifica]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;} |
[modifica]Esempio
Il codice seguente sposta oggetti thread (che a loro volta non sono copiabili) da un contenitore ad un altro. </ p>
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 noncopyablestd :: mossa </ span>(v.begin(), v.end(), std::back_inserter(l));
for(auto& t : l) t.join();
} </div>
You can help to correct and verify the translation. Click here for instructions.
thread 1 ended thread 2 ended thread 3 ended
[modifica]Vedi anche
(C++11) | 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) |