Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the counterpart of std::move in boost library

Tags:

c++

c++11

boost

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.

like image 598
feelfree Avatar asked Aug 04 '16 07:08

feelfree


People also ask

What is std :: move for?

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.

What happens to object after std :: move?

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.

Should you use std :: move?

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).


1 Answers

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.

like image 53
Victor Savu Avatar answered Oct 21 '22 09:10

Victor Savu