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 <boost/move/move.hpp>
#include <boost/optional/optional.hpp>
#include <utility>
#include <vector>

typedef boost::optional<int> data_type;
typedef std::vector<data_type> 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