[Boost.Move] Conflict between std::move and boost::move (Boost 1.49.0)
Hi folks,
Consider the following code (which distilled from a real world example):
#include
Le 10/07/12 23:18, Jonathan Jones a écrit :
Hi folks,
Consider the following code (which distilled from a real world example):
#include
#include #include <utility> #include <vector> typedef boost::optional<int> data_type; typedef std::vector
vector_type; vector_type func() { vector_type vv; return move(vv); }
If I compile this code using Boost 1.49 on Visual Studio 2010, or on a recent version of g++ (e.g. 4.7.1) which supports some C++11 features, the code fails to compile, complaining about ambiguity between std::move and boost::move. Strangely, the code compiles fine with Apple Clang version 3.1. Which compiler has the correct behavior?
Is there a way to work around the compilation problem which doesn't involve explicitly qualifying the calls to move? I'd prefer to use argument-dependent-lookup. Removing the includes of boost/move.hpp is not possible. In the real world example, that header is included indirectly.
I did notice that if I define the macro BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE, the compilation errors disappear. Is this the correct approach for compilers which support std::move? I find it odd that this macro isn't already defined for such compilers.
It seems you have found the solution. Could you create a ticket so that macro is defined when the std library provides std::move? In the meantime you could define the macro yourself. Best, Vicente
On Tue, Jul 10, 2012 at 2:18 PM, Jonathan Jones < Jonathan.Jones@mathworks.com> wrote:
Hi folks,
Consider the following code (which distilled from a real world example):
#include
#include #include <utility> #include <vector> typedef boost::optional<int> data_type; typedef std::vector
vector_type; vector_type func() { vector_type vv; return move(vv); }
If I compile this code using Boost 1.49 on Visual Studio 2010, or on a recent version of g++ (e.g. 4.7.1) which supports some C++11 features, the code fails to compile, complaining about ambiguity between std::move and boost::move. Strangely, the code compiles fine with Apple Clang version 3.1.
Is there a way to work around the compilation problem which doesn't involve explicitly qualifying the calls to move? I'd prefer to use argument-dependent-lookup.
ADL doesn't really seem appropriate here, does it? Sounds like you intend to call std::move regardless of the arguments.
Removing the includes of boost/move.hpp is not possible. In the real world example, that header is included indirectly.
I did notice that if I define the macro BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE, the compilation errors disappear. Is this the correct approach for compilers which support std::move? I find it odd that this macro isn't already defined for such compilers.
Well, (a) based on my quick reading of move.hpp, that looks like it should do the thing you want; and (b) I don't the know the rationale for not defining it for C++11 compilers, perhaps Ion can comment. HTH, - Jeff
El 10/07/2012 23:55, Jeffrey Lee Hellrung, Jr. escribió:
ADL doesn't really seem appropriate here, does it? Sounds like you intend to call std::move regardless of the arguments.
I agree. You should qualify std::move or "using std::move";. You could define another move(xxx) function in another namespace and have the same problem.
I did notice that if I define the macro BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE, the compilation errors disappear. Is this the correct approach for compilers which support std::move? I find it odd that this macro isn't already defined for such compilers.
Well, (a) based on my quick reading of move.hpp, that looks like it should do the thing you want; and (b) I don't the know the rationale for not defining it for C++11 compilers, perhaps Ion can comment.
It was an experiment, as Boost.Config does not detect the presence of std::move. This macro should be activated for compilers with rvalue references plus and an updated standard library. Best, Ion
on Wed Jul 11 2012, Ion Gaztañaga
El 10/07/2012 23:55, Jeffrey Lee Hellrung, Jr. escribió:
ADL doesn't really seem appropriate here, does it? Sounds like you intend to call std::move regardless of the arguments.
I agree. You should qualify std::move or "using std::move";.
The latter doesn't disable ADL; it just makes the std:: version visible without ADL. -- Dave Abrahams BoostPro Computing Software Development Training http://www.boostpro.com Clang/LLVM/EDG Compilers C++ Boost
participants (5)
-
Dave Abrahams
-
Ion Gaztañaga
-
Jeffrey Lee Hellrung, Jr.
-
Jonathan Jones
-
Vicente J. Botet Escriba