Espacios de nombres
Variantes
Acciones

std::move

De cppreference.com
< cpp‎ | utility


 
 
Utilidades de la biblioteca
Escriba apoyo (basic types, RTTI, type traits)
Gestión de memoria dinámica
Gestión de errores
Programa de servicios públicos
Funciones variadic
Fecha y hora
Objetos Function
initializer_list(C++11)
bitset
hash(C++11)
Operadores relacionales
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
Pares y tuplas
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
Cambiar, hacia adelante y mover
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
swap
forward(C++11)
move(C++11)
move_if_noexcept(C++11)
declval(C++11)
 
Defined in header <utility>
template< class T >
typename std::remove_reference<T>::type&& move( T&& t );
(desde C++11)
std::move obtiene una referencia de valor-para su argumento. DVALOR referencias de otro modo sólo se produce por objetos temporales, por lo que el código de biblioteca que se pasa una referencia a un objeto de valor-recursos propietaria tiene la opción (pero no está obligado) para mover' el recurso de la discusión con el fin de ejecutar más rápidamente, dejando la discusión con un valor vacío. El código de la biblioteca tiene la obligación de dejar un valor válido en el argumento, pero a menos que los documentos de tipo o función de lo contrario, no existen otras restricciones sobre el valor del argumento resultante. Esto significa que es más sabio en general a evitar el uso de un argumento pasado de nuevo. Si tiene que volver a utilizarlo, asegúrese de volver a inicializar con un valor conocido antes de hacerlo .
Original:
std::move obtains an rvalue reference to its argument. Rvalue references are otherwise only produced by temporary objects, so library code that's passed an rvalue reference to a resource-owning object has the option (but isn't required) to move the resource out of the argument in order to run more quickly, leaving the argument with an empty value. The library code is required to leave a valid value in the argument, but unless the type or function documents otherwise, there are no other constraints on the resulting argument value. This means that it's generally wisest to avoid using a moved from argument again. If you have to use it again, be sure to re-initialize it with a known value before doing so.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Contenido

[editar] Parámetros

t -
el objeto a ser movido
Original:
the object to be moved
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Valor de retorno

static_cast<typename std::remove_reference<T>::type&&>(t)

[editar] Excepciones

noexcept specification:  
noexcept
  (desde C++11)

[editar] Ejemplo

#include <iostream>
#include <utility>
#include <vector>
#include <string>
int main()
{
    std::string str = "Hello";
    std::vector<std::string> v;
 
    // uses the push_back(const T&) overload, which means 
    // we'll incur the cost of copying str
    v.push_back(str);
    std::cout << "After copy, str is \"" << str << "\"\n";
 
    // uses the rvalue reference push_back(T&&) overload, 
    // which means no strings will copied; instead, the contents
    // of str will be moved into the vector.  This is less
    // expensive, but also means str might now be empty.
    v.push_back(std::move(str));
    std::cout << "After move, str is \"" << str << "\"\n";
 
    std::cout << "The contents of the vector are \"" << v[0]
                                         << "\", \"" << v[1] << "\"\n";
}

Output:

After copy, str is "Hello"
After move, str is ""
The contents of the vector are "Hello", "Hello"

[editar] Complejidad

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

[editar] Ver también

(C++11)
reenvía una función argumento
Original:
forwards a function argument
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla) [edit]
obtiene una referencia de valor-si el constructor movimiento no tira
Original:
obtains an rvalue reference if the move constructor does not throw
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(función de plantilla) [edit]