I am trying to use std::move
in my codes, but the compiler (g++ 4.4) I am using does not support it. Can boost::move
substitute std::move
completely? Thanks.
std::move is used to indicate that an object t may be "moved from", i.e. allowing the efficient transfer of resources from t to another object. In particular, std::move produces an xvalue expression that identifies its argument t . It is exactly equivalent to a static_cast to an rvalue reference type.
std::move is actually just a request to move and if the type of the object has not a move constructor/assign-operator defined or generated the move operation will fall back to a copy.
A: You should use std::move if you want to call functions that support move semantics with an argument which is not an rvalue (temporary expression).
std::move
(and boost::move
when c++0x support is enabled) is just a cast from T&
to T&&
. It does not actually move anything. This means that the specific type of pointer T&&
must be supported by the compiler. GCC supports r-value references since version 4.3, so the boost version should be fine.
However, is there a reason you can't use std::move
from #include <utility>
?
http://en.cppreference.com/w/cpp/utility/move
You just need to make sure to specify -std=c++0x
as a compiler option in order to enable the limited c++11 support that gcc 4.4 has.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With