asio C++ library

PrevUpHomeNext

package (1 of 2 overloads)

Wrap a function object in a packaged task.

template<
    typename Function>
packaged_token< typename decay< Function >::type, std::allocator< void > > package(
    Function && function);

The package function is used to adapt a function object as a packaged task. When this adapter is passed as a completion token to an asynchronous operation, the result of the function object is retuned via a std::future.

Example
std::future<std::size_t> fut =
  my_socket.async_read_some(buffer,
    package([](asio::error_code ec, std::size_t n)
      {
        return ec ? 0 : n;
      }));
...
std::size_t n = fut.get();

PrevUpHomeNext