Boost C++ 库

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb SutterAndrei Alexandrescu, C++ 编码标准

PrevUpHomeNext

io_context::wrap

(已弃用:请使用 bind_executor。) 创建一个新的处理器,它自动在 io_context 上分发被包装的处理器。

template<
    typename Handler>
unspecified wrap(
    Handler handler);

此函数用于创建一个新的处理器函数对象,当调用该对象时,它将自动将被包装的处理器传递给 io_context 对象的 dispatch 函数。

参数

handler

要包装的处理器。 io_context 将根据需要创建处理器对象的副本。处理器的函数签名必须是

void handler(A1 a1, ... An an);
返回值

一个函数对象,当调用该对象时,它将将被包装的处理器传递给 io_context 对象的 dispatch 函数。给定一个具有以下签名的函数对象

R f(A1 a1, ... An an);

如果此函数对象像这样传递给 wrap 函数

io_context.wrap(f);

那么返回值是一个具有以下签名的函数对象

void g(A1 a1, ... An an);

当调用该对象时,执行的代码等效于

boost::asio::dispatch(io_context,
   boost::bind(f, a1, ... an));

PrevUpHomeNext