feelfree
feelfree

Reputation: 11763

the counterpart of std::move in boost library

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.

Upvotes: 11

Views: 3139

Answers (2)

Victor Savu
Victor Savu

Reputation: 981

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.

Upvotes: 11

Serve Laurijssen
Serve Laurijssen

Reputation: 9753

Yes it can

What is Boost.Move?

Rvalue references are a major C++0x feature, enabling move semantics for C++ values. However, we don't need C++0x compilers to take advantage of move semanatics. Boost.Move emulates C++0x move semantics in C++03 compilers and allows writing portable code that works optimally in C++03 and C++0x compilers.

Source: http://www.boost.org/doc/libs/1_59_0_b1/doc/html/move.html

Upvotes: 8

Related Questions