std::move
![]() | 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. |
Defined in header <algorithm> | ||
template<class InputIt, class OutputIt > OutputIt move( InputIt first, InputIt last, OutputIt d_first ); | (a partir do C++ 11) | |
[first, last)
gama, para um outro intervalo de início d_first
. Após esta operação os elementos no intervalo mudou-do ainda irá conter valores válidos do tipo apropriado, mas não necessariamente os mesmos valores de antes da mudança.[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.
Índice |
[editar]Parâmetros
first, last | - | a gama de elementos para se mover 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 | - | o início do intervalo de destino. Se d_first está dentro [first, last) , std::move_backward deve ser utilizado em vez de NJ std :: movimento </ 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 :: movimento </ 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 . |
[editar]Valor de retorno
You can help to correct and verify the translation. Click here for instructions.
[editar]Complexidade
last - first
mover atribuições.last - first
move assignments.You can help to correct and verify the translation. Click here for instructions.
[editar]Possível implementação
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;} |
[editar]Exemplo
O código a seguir move objetos de rosca (que em si não são copiável) de um recipiente para outro. </ 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 :: movimento </ 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
[editar]Veja também
(C++11) | move uma série de elementos para uma nova localização para trás 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. (modelo de função) |