Does std::bind work with move-only types in general, and std::unique_ptr in particular?

前端 未结 1 617
感动是毒
感动是毒 2020-12-04 01:20

I\'m trying to use boost::asio and run into a bit of a quagmire.

I\'m trying to compile the following code:

std::unique_ptr buffer =          


        
相关标签:
1条回答
  • 2020-12-04 02:16

    std::bind works fine with move-only types. However it creates a move-only functor in the process. std::function requires a copy constructible functor. It sounds like boost::asio does too.

    When you call the move-only bind functor, it will pass its bound arguments as lvalues to the target operator(). So if one of your bound arguments is move-only, the target operator() must take that argument by (possibly const) lvalue reference.

    0 讨论(0)
提交回复
热议问题