Are there any problems with boost :: bind with VS2010?

I had the following line of code that compiles only under g ++ and Visual Studio until 2010.

std::vector<Device> device_list;

boost::function<void (Device&, boost::posix_time::time_duration&)> callback = 
  boost::bind(&std::vector<Device>::push_back, &device_list, _1);

Where Deviceis the class, nothing special about it.

Now I just upgraded my version of Visual Studio to 2010, and the compilation failed:

Error   1   error C2780: 'boost::_bi::bind_t<_bi::dm_result<MT::* ,A1>::type,boost::_mfi::dm<M,T>,_bi::list_av_1<A1>::type> boost::bind(M T::* ,A1)' : expects 2 arguments - 3 provided C:\developments\libsystools\trunk\src\upnp_control_point.cpp    95

What is happening and how can I solve it?

Thank.

+5
source share
2 answers

Perhaps this is due to the fact that it vector::push_backnow has 2 overloads through support functions or C ++ 0x, which makes it bindambiguous.

void push_back(
   const Type&_Val
);
void push_back(
   Type&&_Val
);

This should work or use the built-in function suggested by @DeadMG:

std::vector<Device> device_list;

boost::function<void (Device&, boost::posix_time::time_duration&)> callback = 
  boost::bind(static_cast<void (std::vector<Device>::*)( const Device& )>
  (&std::vector<Device>::push_back), &device_list, _1);
+10
source

MSVC10 . , . -, , boost:: std:: function.

std::vector<Device> devices;
std::function<void (Device&, boost::posix_time::time_duration&)> callback = [&](Device& dev, boost::posix_time::time_duration& time) {
    devices.push_back(dev);
};

MSVC10.

+4

All Articles