Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

basic_yield_context::operator[]

Return a yield context that sets the specified error_code.

basic_yield_context operator[](
    boost::system::error_code & ec) const;

By default, when a yield context is used with an asynchronous operation, a non-success error_code is converted to system_error and thrown. This operator may be used to specify an error_code object that should instead be set with the asynchronous operation's result. For example:

template <typename Handler>
void my_coroutine(basic_yield_context<Handler> yield)
{
  ...
  std::size_t n = my_socket.async_read_some(buffer, yield[ec]);
  if (ec)
  {
    // An error occurred.
  }
  ...
}

PrevUpHomeNext