Search code examples
c++visual-c++c++11visual-c++-2010move-semantics

VS2010 bind implementation doesn't support move-only types?


I've found that the following code doesn't compile in Visual Studio 2010 (but works fine in GCC):

using namespace std;
unique_ptr<string> up(new string("abc"));
auto bound = bind(&string::size, move(up));
bound();

The error I get is:

'std::unique_ptr<_Ty>::unique_ptr' : cannot access private member declared in class 'std::unique_ptr<_Ty>'

Is it because the VS2010 bind implementation just doesn't support move only types?


Solution

  • Your guess is correct: The Visual C++ 2010 implementation of std::bind is not move-aware. See the bug report, "std::bind and std::function are not move-aware."

    This is fixed in the forthcoming version, Visual C++ 11. The fix should be present in the Visual C++ Developer Preview that was released in September.