Commit e8234af5 authored by Dominik Charousset's avatar Dominik Charousset

Simply functor_attachable implementation

parent 35737b2f
......@@ -11,41 +11,31 @@
namespace caf::detail {
template <class F,
int Args = tl_size<typename get_callable_trait<F>::arg_types>::value>
struct functor_attachable : attachable {
static_assert(Args == 1 || Args == 2,
"Only 0, 1 or 2 arguments for F are supported");
F functor_;
functor_attachable(F arg) : functor_(std::move(arg)) {
// nop
}
void actor_exited(const error& fail_state, execution_unit*) override {
functor_(fail_state);
}
static constexpr size_t token_type = attachable::token::anonymous;
};
template <class F>
struct functor_attachable<F, 2> : attachable {
F functor_;
functor_attachable(F arg) : functor_(std::move(arg)) {
// nop
}
void actor_exited(const error& x, execution_unit* y) override {
functor_(x, y);
}
};
class functor_attachable : public attachable {
public:
static constexpr size_t num_args
= tl_size<typename get_callable_trait<F>::arg_types>::value;
template <class F>
struct functor_attachable<F, 0> : attachable {
F functor_;
functor_attachable(F arg) : functor_(std::move(arg)) {
static_assert(num_args < 3, "Only 0, 1 or 2 arguments for F are supported");
explicit functor_attachable(F fn) : fn_(std::move(fn)) {
// nop
}
void actor_exited(const error&, execution_unit*) override {
functor_();
void actor_exited(const error& fail_state, execution_unit* host) override {
if constexpr (num_args == 0)
fn_();
else if constexpr (num_args == 1)
fn_(fail_state);
else
fn_(fail_state, host);
}
static constexpr size_t token_type = attachable::token::anonymous;
private:
F fn_;
};
} // namespace caf::detail
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment