Commit 6a60637a authored by Dominik Charousset's avatar Dominik Charousset

return result from partial_function and behavior

parent b7c862a4
......@@ -101,7 +101,7 @@ class behavior {
* @copydoc partial_function::operator()()
*/
template<typename T>
inline bool operator()(T&& arg);
inline optional<any_tuple> operator()(T&& arg);
/**
* @brief Adds a continuation to this behavior that is executed
......@@ -159,8 +159,8 @@ inline const util::duration& behavior::timeout() const {
}
template<typename T>
inline bool behavior::operator()(T&& arg) {
return (m_impl) && m_impl->invoke(std::forward<T>(arg));
inline optional<any_tuple> behavior::operator()(T&& arg) {
return (m_impl) ? m_impl->invoke(std::forward<T>(arg)) : none;
}
......
......@@ -99,7 +99,7 @@ class partial_function {
* does <b>not</b> evaluate guards.
*/
template<typename T>
inline bool operator()(T&& arg);
inline optional<any_tuple> operator()(T&& arg);
/**
* @brief Adds a fallback which is used where
......@@ -162,8 +162,8 @@ inline bool partial_function::defined_at(const any_tuple& value) {
}
template<typename T>
inline bool partial_function::operator()(T&& arg) {
return (m_impl) && m_impl->invoke(std::forward<T>(arg));
inline optional<any_tuple> partial_function::operator()(T&& arg) {
return (m_impl) ? m_impl->invoke(std::forward<T>(arg)) : none;
}
template<typename... Ts>
......
......@@ -171,7 +171,14 @@ int main() {
CPPA_CHECK_EQUAL(expr19(expr19_tup), 2);
partial_function expr20 = expr19;
enable_case1 = false;
CPPA_CHECK_EQUAL(expr20(expr19_tup), 1);
CPPA_CHECK(expr20(expr19_tup) == make_any_tuple(1));
partial_function expr21 {
on(atom("add"), arg_match) >> [](int a, int b) {
return a + b;
}
};
CPPA_CHECK(expr21(make_any_tuple(atom("add"), 1, 2)) == make_any_tuple(3));
CPPA_CHECK(!expr21(make_any_tuple(atom("sub"), 1, 2)));
}
/* test 'match' function */ {
auto res0 = match(5) (
......@@ -277,7 +284,7 @@ int main() {
std::string last_invoked_fun;
# define bhvr_check(pf, tup, expected_result, str) { \
last_invoked_fun = ""; \
CPPA_CHECK_EQUAL(pf(tup), expected_result); \
CPPA_CHECK_EQUAL(static_cast<bool>(pf(tup)), expected_result); \
CPPA_CHECK_EQUAL(last_invoked_fun, str); \
}
/* test if match hints are evaluated properly */ {
......
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