An example for announce with getter and setter member functions.The output of this example program is:
foo(1, 2)
#include <utility>
#include <iostream>
#include "caf/all.hpp"
using std::cout;
using std::endl;
using std::make_pair;
class foo {
int a_;
int b_;
public:
foo(int a0 = 0, int b0 = 0) : a_(a0), b_(b0) { }
foo(const foo&) = default;
foo& operator=(const foo&) = default;
int a() const { return a_; }
void set_a(
int val) { a_ =
val; }
int b() const { return b_; }
void set_b(
int val) { b_ =
val; }
};
bool operator==(const foo& lhs, const foo& rhs) {
return lhs.a() == rhs.a()
&& lhs.b() == rhs.b();
}
self->become (
on<foo>() >> [=](
const foo&
val) {
aout(self) << "foo("
<< val.a() << ", "
<< val.b() << ")"
<< endl;
self->quit();
}
);
}
int main(int, char**) {
announce<foo>("foo", make_pair(&foo::a, &foo::set_a),
make_pair(&foo::b, &foo::set_b));
{
self->send(t, foo{1, 2});
}
return 0;
}