Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 778 Bytes

refman-plain.md

File metadata and controls

39 lines (30 loc) · 778 Bytes

class plain (clause modifier)

<< Back to reference manual

A clause modifier used for handle_command functions that interpret commands as functions (i.e., they are self- and tail-resumptive). No context switching, no explicit resumption.

template <typename Cmd>
struct plain { };

Usage:

struct Add : command<int> {
  int x, y;
};

class Calculator : public flat_handler<void, plain<Add>> {
  int handle_command(Add c) override  // - no "resumption" argument
                                      // - return type that of the command, not handler
  {
    return c.x + c.y;
  }
};

int main()
{
  handle<Calculator>([](){
    std::cout << "2 + 5 = " << invoke_command<Add>({{}, 2, 5}) << std::endl;
  });
}

Output:

2 + 5 = 7