Skip to content

Latest commit

 

History

History
57 lines (38 loc) · 1.92 KB

refman-wrap.md

File metadata and controls

57 lines (38 loc) · 1.92 KB

function wrap

<< Back to reference manual

template <typename H, typename... Args>
resumption<typename H::answer_type()> wrap(
    int64_t label, std::function<typename H::body_type()> body, Args&&... args);

template <typename H, typename A, typename... Args>
resumption<typename H::answer_type(A)> wrap(
    int64_t label, std::function<typename H::body_type(A)> body, Args&&... args);

template <typename H, typename... Args>
resumption<typename H::answer_type()> wrap(
    std::function<typename H::body_type()> body, Args&&... args);

template <typename H, typename A, typename... Args>
resumption<typename H::answer_type(A)> wrap(
    std::function<typename H::body_type(A)> body, Args&&... args);

Wraps a computation in a handler, but doesn't execute it. Instead, the computation together with a handler are returned as a suspended computation (= resumption).

  • typename H - The type of the handler that is used to handle body.

  • typename... Args - Arguments supplied to the constructor of H.

  • int64_t label - Explicit label of the handler. If no label is given, this handler is used based on the types of the commandss of H (the innermost handler that handles the invoked command is used).

  • std::function<typename H::body_type()> body, std::function<typename H::body_type(A)> body- The wrapped function.

  • Return value resumption<typename H::answer_type(A)> - The resumption that corresponds to body wrapped in a handler H.

Semantically, for a function std::function<T()> foo, the expression

wrap<H>(foo)

is equivalent to

resumption<T()>([=](){ return handle<H>(foo); })

If the function has an argument, it becomes the Out type of the resumption. That is, for a function std::function<T(A)> foo, the expression

wrap<H>(foo)

is equivalent to

resumption<T(A)>([=](A a){ return handle<H>(std::bind(foo, a)); })