asio C++ library

PrevUpHomeNext

use_future_t::operator()

Wrap a function object in a packaged task.

template<
    typename Function>
unspecified operator()(
    Function && f) const;

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,
    use_future([](asio::error_code ec, std::size_t n)
      {
        return ec ? 0 : n;
      }));
...
std::size_t n = fut.get();

PrevUpHomeNext