Commit 00f15911 authored by neverlord's avatar neverlord

guard expressions

parent 3652f62e
...@@ -151,6 +151,7 @@ nobase_library_include_HEADERS = \ ...@@ -151,6 +151,7 @@ nobase_library_include_HEADERS = \
cppa/fsm_actor.hpp \ cppa/fsm_actor.hpp \
cppa/get.hpp \ cppa/get.hpp \
cppa/group.hpp \ cppa/group.hpp \
cppa/guard_expr.hpp \
cppa/intrusive/forward_iterator.hpp \ cppa/intrusive/forward_iterator.hpp \
cppa/intrusive/single_reader_queue.hpp \ cppa/intrusive/single_reader_queue.hpp \
cppa/intrusive/singly_linked_list.hpp \ cppa/intrusive/singly_linked_list.hpp \
...@@ -192,7 +193,6 @@ nobase_library_include_HEADERS = \ ...@@ -192,7 +193,6 @@ nobase_library_include_HEADERS = \
cppa/util/enable_if.hpp \ cppa/util/enable_if.hpp \
cppa/util/fiber.hpp \ cppa/util/fiber.hpp \
cppa/util/fixed_vector.hpp \ cppa/util/fixed_vector.hpp \
cppa/util/guard.hpp \
cppa/util/if_else.hpp \ cppa/util/if_else.hpp \
cppa/util/is_array_of.hpp \ cppa/util/is_array_of.hpp \
cppa/util/is_builtin.hpp \ cppa/util/is_builtin.hpp \
......
...@@ -258,5 +258,5 @@ cppa/detail/tuple_view.hpp ...@@ -258,5 +258,5 @@ cppa/detail/tuple_view.hpp
cppa/detail/container_tuple_view.hpp cppa/detail/container_tuple_view.hpp
cppa/detail/matches.hpp cppa/detail/matches.hpp
unit_testing/test__match.cpp unit_testing/test__match.cpp
cppa/guard_expr.hpp
src/pattern.cpp src/pattern.cpp
cppa/util/guard.hpp
...@@ -163,7 +163,7 @@ enum mapping_policy ...@@ -163,7 +163,7 @@ enum mapping_policy
map_to_option map_to_option
}; };
template<mapping_policy, class Pattern> template<mapping_policy, class Pattern> // do_not_map
struct pattern_policy struct pattern_policy
{ {
Pattern m_pattern; Pattern m_pattern;
......
...@@ -267,9 +267,9 @@ template<typename T> ...@@ -267,9 +267,9 @@ template<typename T>
struct tdata_from_type_list; struct tdata_from_type_list;
template<typename... T> template<typename... T>
struct tdata_from_type_list<cppa::util::type_list<T...>> struct tdata_from_type_list<util::type_list<T...>>
{ {
typedef cppa::detail::tdata<T...> type; typedef tdata<T...> type;
}; };
} } // namespace cppa::detail } } // namespace cppa::detail
......
This diff is collapsed.
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "cppa/anything.hpp" #include "cppa/anything.hpp"
#include "cppa/behavior.hpp" #include "cppa/behavior.hpp"
#include "cppa/any_tuple.hpp" #include "cppa/any_tuple.hpp"
#include "cppa/guard_expr.hpp"
#include "cppa/partial_function.hpp" #include "cppa/partial_function.hpp"
#include "cppa/util/duration.hpp" #include "cppa/util/duration.hpp"
...@@ -98,7 +99,9 @@ class rvalue_builder ...@@ -98,7 +99,9 @@ class rvalue_builder
typedef typename pattern_from_type_list<types>::type pattern_type; typedef typename pattern_from_type_list<types>::type pattern_type;
std::unique_ptr<value_matcher> m_vm; typedef std::unique_ptr<value_matcher> vm_ptr;
vm_ptr m_vm;
template<typename F> template<typename F>
partial_function cr_rvalue(F&& f, std::integral_constant<bool, true>) partial_function cr_rvalue(F&& f, std::integral_constant<bool, true>)
...@@ -123,6 +126,30 @@ class rvalue_builder ...@@ -123,6 +126,30 @@ class rvalue_builder
public: public:
template<operator_id OP, typename F, typename S>
rvalue_builder& when(guard_expr<OP, F, S> ge)
{
typedef guard_expr<OP, F, S> gtype;
struct vm_impl : value_matcher
{
vm_ptr m_ptr;
gtype m_ge;
vm_impl(vm_ptr&& ptr, gtype&& g) : m_ptr(std::move(ptr)), m_ge(std::move(g)) { }
bool operator()(any_tuple const& tup) const
{
static_assert(std::is_same<decltype(ge_invoke_any<types>(m_ge, tup)), bool>::value,
"guard expression does not return a boolean");
if ((*m_ptr)(tup))
{
return ge_invoke_any<types>(m_ge, tup);
}
return false;
}
};
m_vm.reset(new vm_impl(std::move(m_vm), std::move(ge)));
return *this;
}
template<typename... Args> template<typename... Args>
rvalue_builder(Args&&... args) rvalue_builder(Args&&... args)
: m_vm(pattern_type::get_value_matcher(std::forward<Args>(args)...)) : m_vm(pattern_type::get_value_matcher(std::forward<Args>(args)...))
......
...@@ -82,8 +82,7 @@ struct apply_tuple_util<Result, IsManipulator, 1, 0> ...@@ -82,8 +82,7 @@ struct apply_tuple_util<Result, IsManipulator, 1, 0>
}; };
template<typename F, template<typename...> class Tuple, typename... T> template<typename F, template<typename...> class Tuple, typename... T>
auto apply_tuple(F&& fun, Tuple<T...>& tup) typename get_result_type<F>::type apply_tuple(F&& fun, Tuple<T...>& tup)
-> typename get_result_type<F>::type
{ {
typedef typename get_result_type<F>::type result_type; typedef typename get_result_type<F>::type result_type;
typedef typename get_arg_types<F>::types fun_args; typedef typename get_arg_types<F>::types fun_args;
...@@ -98,8 +97,7 @@ auto apply_tuple(F&& fun, Tuple<T...>& tup) ...@@ -98,8 +97,7 @@ auto apply_tuple(F&& fun, Tuple<T...>& tup)
} }
template<typename F, template<typename...> class Tuple, typename... T> template<typename F, template<typename...> class Tuple, typename... T>
auto apply_tuple(F&& fun, Tuple<T...> const& tup) typename get_result_type<F>::type apply_tuple(F&& fun, Tuple<T...> const& tup)
-> typename get_result_type<F>::type
{ {
typedef typename get_result_type<F>::type result_type; typedef typename get_result_type<F>::type result_type;
typedef typename get_arg_types<F>::types fun_args; typedef typename get_arg_types<F>::types fun_args;
...@@ -113,16 +111,24 @@ auto apply_tuple(F&& fun, Tuple<T...> const& tup) ...@@ -113,16 +111,24 @@ auto apply_tuple(F&& fun, Tuple<T...> const& tup)
::apply(std::forward<F>(fun), tup); ::apply(std::forward<F>(fun), tup);
} }
template<typename Result, typename F, template<typename...> class Tuple, typename... T> template<typename Result, size_t From, size_t To,
Result unchecked_apply_tuple(F&& fun, Tuple<T...>& tup) typename F, template<typename...> class Tuple, typename... T>
Result unchecked_apply_tuple_in_range(F&& fun, Tuple<T...> const& tup)
{ {
static constexpr size_t tup_size = sizeof...(T); return apply_tuple_util<Result, false, From, To>
static constexpr size_t from = 0;
static constexpr size_t to = tup_size - 1;
return apply_tuple_util<Result, false, from, to>
::apply(std::forward<F>(fun), tup); ::apply(std::forward<F>(fun), tup);
} }
// applies all values of @p tup to @p fun
// does not evaluate result type of functor
template<typename Result, typename F,
template<typename...> class Tuple, typename... T>
Result unchecked_apply_tuple(F&& fun, Tuple<T...> const& tup)
{
return unchecked_apply_tuple_in_range<Result, 0, sizeof...(T) - 1>
(std::forward<F>(fun), tup);
}
} } // namespace cppa::util } } // namespace cppa::util
#endif // APPLY_TUPLE_HPP #endif // APPLY_TUPLE_HPP
...@@ -314,6 +314,20 @@ struct tl_concat<type_list<ListATypes...>, type_list<ListBTypes...> > ...@@ -314,6 +314,20 @@ struct tl_concat<type_list<ListATypes...>, type_list<ListBTypes...> >
typedef type_list<ListATypes..., ListBTypes...> type; typedef type_list<ListATypes..., ListBTypes...> type;
}; };
// list list::push_back(list, type)
template<typename List, typename What>
struct tl_push_back;
/**
* @brief Appends @p What to given list.
*/
template<typename... ListTypes, typename What>
struct tl_push_back<type_list<ListTypes...>, What>
{
typedef type_list<ListTypes..., What> type;
};
// list list::appy(trait) // list list::appy(trait)
template<typename List, template<typename> class Trait> template<typename List, template<typename> class Trait>
......
This diff is collapsed.
...@@ -23,7 +23,7 @@ using std::endl; ...@@ -23,7 +23,7 @@ using std::endl;
using namespace cppa; using namespace cppa;
// GCC 4.7 supports non-static member initialization // GCC 4.7 supports non-static member initialization
#if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 7) #if 0 //(__GNUC__ >= 4) && (__GNUC_MINOR__ >= 7)
struct event_testee : public fsm_actor<event_testee> struct event_testee : public fsm_actor<event_testee>
{ {
......
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