Commit 129e05ad authored by neverlord's avatar neverlord

support 'val<type>' syntax in patterns

parent 89b9ff7f
...@@ -66,7 +66,23 @@ struct is_boxed< util::wrapped<T> > ...@@ -66,7 +66,23 @@ struct is_boxed< util::wrapped<T> >
static const bool value = true; static const bool value = true;
}; };
template<typename T>
struct is_boxed<util::wrapped<T>()>
{
static const bool value = true;
};
template<typename T>
struct is_boxed<util::wrapped<T>(&)()>
{
static const bool value = true;
};
template<typename T>
struct is_boxed<util::wrapped<T>(*)()>
{
static const bool value = true;
};
} } // namespace cppa::detail } } // namespace cppa::detail
......
...@@ -99,6 +99,14 @@ struct tdata<Head, Tail...> : tdata<Tail...> ...@@ -99,6 +99,14 @@ struct tdata<Head, Tail...> : tdata<Tail...>
{ {
} }
// allow initialization with a function pointer or reference
// returning a wrapped<Head>
template<typename...Args>
tdata(util::wrapped<Head>(*)(), Args const&... vals)
: super(vals...), head()
{
}
inline tdata<Tail...>& tail() inline tdata<Tail...>& tail()
{ {
// upcast // upcast
......
...@@ -47,6 +47,24 @@ struct unboxed< util::wrapped<T> > ...@@ -47,6 +47,24 @@ struct unboxed< util::wrapped<T> >
typedef typename util::wrapped<T>::type type; typedef typename util::wrapped<T>::type type;
}; };
template<typename T>
struct unboxed<util::wrapped<T> (&)()>
{
typedef typename util::wrapped<T>::type type;
};
template<typename T>
struct unboxed<util::wrapped<T> ()>
{
typedef typename util::wrapped<T>::type type;
};
template<typename T>
struct unboxed<util::wrapped<T> (*)()>
{
typedef typename util::wrapped<T>::type type;
};
} } // namespace cppa::detail } } // namespace cppa::detail
#endif // UNBOXED_HPP #endif // UNBOXED_HPP
...@@ -98,8 +98,8 @@ class invoke_rule_builder ...@@ -98,8 +98,8 @@ class invoke_rule_builder
template<typename... Args> template<typename... Args>
invoke_rule_builder(Args const&... args) invoke_rule_builder(Args const&... args)
: m_pattern(new pattern_type(args...))
{ {
m_pattern.reset(new pattern_type(args...));
} }
template<typename F> template<typename F>
......
...@@ -68,7 +68,7 @@ size_t test__pattern() ...@@ -68,7 +68,7 @@ size_t test__pattern()
CPPA_CHECK_EQUAL(str, "hello foo"); CPPA_CHECK_EQUAL(str, "hello foo");
lambda_invoked[1] = true; lambda_invoked[1] = true;
}, },
on("1", val<int>(), any_vals) >> [&](int value) on("1", val<int>, any_vals) >> [&](int value)
{ {
CPPA_CHECK_EQUAL(value, 2); CPPA_CHECK_EQUAL(value, 2);
lambda_invoked[2] = true; lambda_invoked[2] = true;
......
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