the counterpart of std::move in boost library

只愿长相守 提交于 2020-01-23 04:50:13

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/38761626/the-counterpart-of-stdmove-in-boost-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!