Commit 0b62812c authored by Dominik Charousset's avatar Dominik Charousset

refined `detail::valid_input_predicate`

this patch allows typed_behavior to handle multiple message handlers
using the same input types but different output types;
however, sync_send(...).{then|await} are not ready for multiple
result types yet
parent 9563d041
......@@ -67,9 +67,20 @@ struct unbox_typed_continue_helper<util::type_list<typed_continue_helper<List>>>
typedef List type;
};
template<class Input, class RepliesToWith>
struct same_input : std::is_same<Input, typename RepliesToWith::input_types> { };
template<class Output, class RepliesToWith>
struct same_output_or_skip_message_t {
typedef typename RepliesToWith::output_types other;
static constexpr bool value =
std::is_same<Output, typename RepliesToWith::output_types>::value
|| std::is_same<Output, util::type_list<skip_message_t>>::value;
};
template<typename SList>
struct valid_input_predicate {
typedef typename input_only<SList>::type s_inputs;
//typedef typename input_only<SList>::type s_inputs;
template<typename Expr>
struct inner {
typedef typename Expr::input_types input_types;
......@@ -77,17 +88,29 @@ struct valid_input_predicate {
typename Expr::output_types
>::type
output_types;
static constexpr int pos = util::tl_find<s_inputs, input_types>::value;
static_assert(pos != -1, "cannot assign given match expression to "
"typed behavior, because the expression "
"contains at least one pattern that is "
"not defined in the actor's type");
typedef typename util::tl_at<SList, pos>::type s_element;
typedef typename s_element::output_types s_out;
static constexpr bool value =
std::is_same<output_types, s_out>::value
|| std::is_same<output_types, skip_list>::value;
static_assert(value, "wtf");
// get matching elements for input type
typedef typename util::tl_filter<
SList,
util::tbind<same_input, input_types>::template type
>::type
filtered_slist;
static_assert(util::tl_size<filtered_slist>::value > 0,
"cannot assign given match expression to "
"typed behavior, because the expression "
"contains at least one pattern that is "
"not defined in the actor's type");
static constexpr bool value = util::tl_exists<
filtered_slist,
util::tbind<
same_output_or_skip_message_t,
output_types
>::template type
>::value;
// check whether given output matches in the filtered list
static_assert(value,
"cannot assign given match expression to "
"typed behavior, because at least one return "
"type does not match");
};
};
......
......@@ -315,6 +315,52 @@ void test_sending_typed_actors() {
self->send_exit(aut, exit_reason::user_shutdown);
}
/******************************************************************************
* returning different types *
******************************************************************************/
// might be implemented one fine day
/*
typedef typed_actor<
replies_to<int>::with<int>,
replies_to<int>::with<float>
>
different_results_t;
different_results_t::behavior_type different_results_testee() {
return {
on_arg_match.when(cppa::placeholders::_x1 >= 5) >> [](int) {
return 1;
},
[](int) {
return 0.1f;
}
};
}
void test_returning_different_types() {
scoped_actor self;
auto testee = self->spawn_typed(different_results_testee);
self->sync_send(testee, 5).await(
[](int i) {
CPPA_CHECK_EQUAL(i, 1);
},
[&](float) {
CPPA_UNEXPECTED_MSG(self);
}
);
self->sync_send(testee, 4).await(
[](float f) {
CPPA_CHECK_EQUAL(f, 0.1f);
},
[&](int) {
CPPA_UNEXPECTED_MSG(self);
}
);
}
*/
} // namespace <anonymous>
/******************************************************************************
......
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