Boost C++ Libraries 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.


Request the io_context to invoke the given function object.

    typename Function,
    typename OtherAllocator>
void defer(
    Function && f,
    const OtherAllocator & a) const;

This function is used to ask the io_context to execute the given function object. The function object will never be executed inside defer(). Instead, it will be scheduled to run on the io_context.

If the current thread belongs to the io_context, defer() will delay scheduling the function object until the current thread returns control to the pool.



The function object to be called. The executor will make a copy of the handler object as required. The function signature of the function object must be:

void function();


An allocator that may be used by the executor to allocate the internal storage needed for function invocation.