Commit e6484fce authored by Dominik Charousset's avatar Dominik Charousset

Add `assign` to `behavior` and `message_handler`

parent 6e4e80ff
......@@ -60,11 +60,8 @@ class behavior {
* and up to one timeout (if set, the timeout has to be the last argument).
*/
template <class T, class... Ts>
behavior(const T& arg, Ts&&... args)
: m_impl(detail::match_expr_concat(
detail::lift_to_match_expr(arg),
detail::lift_to_match_expr(std::forward<Ts>(args))...)) {
// nop
behavior(const T& arg, Ts&&... args) {
assign(arg, std::forward<Ts>(args)...);
}
/**
......@@ -86,6 +83,16 @@ class behavior {
// nop
}
/**
* Assigns new handlers.
*/
template <class T, class... Ts>
void assign(T&& v, Ts&&... vs) {
m_impl = detail::match_expr_concat(
detail::lift_to_match_expr(std::forward<T>(v)),
detail::lift_to_match_expr(std::forward<Ts>(vs))...);
}
/**
* Invokes the timeout callback if set.
*/
......
......@@ -81,11 +81,18 @@ class message_handler {
* functors, or other message handlers.
*/
template <class T, class... Ts>
message_handler(const T& arg, Ts&&... args)
: m_impl(detail::match_expr_concat(
detail::lift_to_match_expr(arg),
detail::lift_to_match_expr(std::forward<Ts>(args))...)) {
// nop
message_handler(const T& v, Ts&&... vs) {
assign(v, std::forward<Ts>(vs)...);
}
/**
* Assigns new message handlers.
*/
template <class T, class... Ts>
void assign(T&& v, Ts&&... vs) {
m_impl = detail::match_expr_concat(
detail::lift_to_match_expr(std::forward<T>(v)),
detail::lift_to_match_expr(std::forward<Ts>(vs))...);
}
/**
......
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