Are there boost::bind issues with VS2010?

后端 未结 2 1571
长发绾君心
长发绾君心 2021-01-18 21:00

I had the following code line which compiles just fine under g++ and Visual Studio prior to 2010.

std::vector device_list;

boost::function<         


        
相关标签:
2条回答
  • 2021-01-18 21:13

    There are issues with binding in MSVC10. This isn't the first post I've seen reporting problems with it. Secondly, it's completely and totally redundant with the introduction of lambdas, and boost::function has been superseded by 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);
    };
    

    There is no need to use binding in MSVC10.

    0 讨论(0)
  • 2021-01-18 21:14

    This is probably because vector::push_back now has 2 overloads through support or C++0x features, making the bind ambiguous.

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

    This should work, or use the built-in function suggested in @DeadMG's answer:

    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);
    
    0 讨论(0)
提交回复
热议问题