Boost async_* functions and shared_ptr's

后端 未结 5 1755
心在旅途
心在旅途 2020-11-29 07:15

I frequently see this pattern in code, binding shared_from_this as the first parameter to a member function and dispatching the result using an async_*

5条回答
  •  我在风中等你
    2020-11-29 08:20

    It goes like this:

    1) Boost.Bind documentation states:

    "[Note: mem_fn creates function objects that are able to accept a pointer, a reference, or a smart pointer to an object as its first argument; for additional information, see the mem_fn documentation.]"

    2) mem_fn documentation says:

    When the function object is invoked with a first argument x that is neither a pointer nor a reference to the appropriate class (X in the example above), it uses get_pointer(x) to obtain a pointer from x. Library authors can "register" their smart pointer classes by supplying an appropriate get_pointer overload, allowing mem_fn to recognize and support them.

    So, pointer or smart-pointer is stored in the binder as-is, until its invocation.

提交回复
热议问题