Commit ee62b236 authored by neverlord's avatar neverlord

guards

parent cdd9aa4d
...@@ -80,7 +80,9 @@ class rvalue_builder ...@@ -80,7 +80,9 @@ class rvalue_builder
typedef util::arg_match_t arg_match_t; typedef util::arg_match_t arg_match_t;
typedef util::type_list<TypeList...> raw_types; typedef util::type_list<
typename detail::implicit_conversions<TypeList>::type...>
raw_types;
static constexpr bool is_complete = static constexpr bool is_complete =
!std::is_same<arg_match_t, typename raw_types::back>::value; !std::is_same<arg_match_t, typename raw_types::back>::value;
...@@ -94,12 +96,7 @@ class rvalue_builder ...@@ -94,12 +96,7 @@ class rvalue_builder
static_assert(util::tl_find<types, arg_match_t>::value == -1, static_assert(util::tl_find<types, arg_match_t>::value == -1,
"arg_match is allowed only as last parameter for on()"); "arg_match is allowed only as last parameter for on()");
typedef typename util::tl_apply<types, typedef typename pattern_from_type_list<types>::type pattern_type;
detail::implicit_conversions>::type
converted_types;
typedef typename pattern_from_type_list<converted_types>::type
pattern_type;
std::unique_ptr<value_matcher> m_vm; std::unique_ptr<value_matcher> m_vm;
...@@ -115,11 +112,11 @@ class rvalue_builder ...@@ -115,11 +112,11 @@ class rvalue_builder
{ {
using namespace ::cppa::util; using namespace ::cppa::util;
typedef typename get_callable_trait<F>::type ctrait; typedef typename get_callable_trait<F>::type ctrait;
typedef typename ctrait::arg_types raw_types; typedef typename ctrait::arg_types raw_arg_types;
static_assert(raw_types::size > 0, "functor has no arguments"); static_assert(raw_types::size > 0, "functor has no arguments");
typedef typename tl_apply<raw_types,rm_ref>::type new_types; typedef typename tl_apply<raw_arg_types,rm_ref>::type arg_types;
typedef typename tl_concat<converted_types,new_types>::type types; typedef typename tl_concat<types,arg_types>::type full_types;
typedef typename pattern_from_type_list<types>::type epattern; typedef typename pattern_from_type_list<full_types>::type epattern;
return get_invokable_impl<epattern>(std::forward<F>(f), return get_invokable_impl<epattern>(std::forward<F>(f),
std::move(m_vm)); std::move(m_vm));
} }
......
...@@ -87,13 +87,13 @@ struct value_matcher ...@@ -87,13 +87,13 @@ struct value_matcher
const bool is_dummy; const bool is_dummy;
inline value_matcher(bool dummy_impl = false) : is_dummy(dummy_impl) { } inline value_matcher(bool dummy_impl = false) : is_dummy(dummy_impl) { }
virtual ~value_matcher(); virtual ~value_matcher();
virtual bool operator()(any_tuple const&) = 0; virtual bool operator()(any_tuple const&) const = 0;
}; };
struct dummy_matcher : value_matcher struct dummy_matcher : value_matcher
{ {
inline dummy_matcher() : value_matcher(true) { } inline dummy_matcher() : value_matcher(true) { }
bool operator()(any_tuple const&); bool operator()(any_tuple const&) const;
}; };
struct cmp_helper struct cmp_helper
...@@ -135,7 +135,7 @@ class value_matcher_impl<wildcard_position::nil, ...@@ -135,7 +135,7 @@ class value_matcher_impl<wildcard_position::nil,
template<typename... Args> template<typename... Args>
value_matcher_impl(Args&&... args) : m_values(std::forward<Args>(args)...) { } value_matcher_impl(Args&&... args) : m_values(std::forward<Args>(args)...) { }
bool operator()(any_tuple const& tup) bool operator()(any_tuple const& tup) const
{ {
cmp_helper h{tup}; cmp_helper h{tup};
return util::static_foreach<0, sizeof...(Vs)>::eval(m_values, h); return util::static_foreach<0, sizeof...(Vs)>::eval(m_values, h);
...@@ -177,7 +177,7 @@ class value_matcher_impl<wildcard_position::leading, ...@@ -177,7 +177,7 @@ class value_matcher_impl<wildcard_position::leading,
template<typename... Args> template<typename... Args>
value_matcher_impl(Args&&... args) : m_values(std::forward<Args>(args)...) { } value_matcher_impl(Args&&... args) : m_values(std::forward<Args>(args)...) { }
bool operator()(any_tuple const& tup) bool operator()(any_tuple const& tup) const
{ {
cmp_helper h{tup, tup.size() - sizeof...(Ts)}; cmp_helper h{tup, tup.size() - sizeof...(Ts)};
return util::static_foreach<0, sizeof...(Vs)>::eval(m_values, h); return util::static_foreach<0, sizeof...(Vs)>::eval(m_values, h);
...@@ -198,7 +198,7 @@ class value_matcher_impl<wildcard_position::in_between, ...@@ -198,7 +198,7 @@ class value_matcher_impl<wildcard_position::in_between,
template<typename... Args> template<typename... Args>
value_matcher_impl(Args&&... args) : m_values(std::forward<Args>(args)...) { } value_matcher_impl(Args&&... args) : m_values(std::forward<Args>(args)...) { }
bool operator()(any_tuple const& tup) bool operator()(any_tuple const& tup) const
{ {
static constexpr size_t wcpos = static constexpr size_t wcpos =
static_cast<size_t>(util::tl_find<util::type_list<Ts...>, anything>::value); static_cast<size_t>(util::tl_find<util::type_list<Ts...>, anything>::value);
...@@ -225,7 +225,7 @@ class value_matcher_impl<wildcard_position::multiple, ...@@ -225,7 +225,7 @@ class value_matcher_impl<wildcard_position::multiple,
template<typename... Args> template<typename... Args>
value_matcher_impl(Args&&...) { } value_matcher_impl(Args&&...) { }
bool operator()(any_tuple const&) bool operator()(any_tuple const&) const
{ {
throw std::runtime_error("not implemented yet, sorry"); throw std::runtime_error("not implemented yet, sorry");
} }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#ifndef APPLY_TUPLE_HPP #ifndef APPLY_TUPLE_HPP
#define APPLY_TUPLE_HPP #define APPLY_TUPLE_HPP
#include "cppa/get.hpp"
#include "cppa/util/enable_if.hpp" #include "cppa/util/enable_if.hpp"
#include "cppa/util/disable_if.hpp" #include "cppa/util/disable_if.hpp"
#include "cppa/util/is_manipulator.hpp" #include "cppa/util/is_manipulator.hpp"
...@@ -38,40 +39,43 @@ ...@@ -38,40 +39,43 @@
namespace cppa { namespace util { namespace cppa { namespace util {
template<size_t... Range> template<typename Result, bool IsManipulator, size_t... Range>
struct apply_tuple_impl struct apply_tuple_impl
{ {
template<typename F, template<typename...> class Tuple, typename... T> template<typename F, template<typename...> class Tuple, typename... T>
static auto apply(F&& f, Tuple<T...> const& args, static Result apply(F&& f, Tuple<T...> const& args)
typename disable_if<is_manipulator<F>, int>::type = 0)
-> typename get_result_type<F>::type
{ {
return f(get<Range>(args)...); return f(get<Range>(args)...);
} }
};
template<typename Result, size_t... Range>
struct apply_tuple_impl<Result, true, Range...>
{
template<typename F, template<typename...> class Tuple, typename... T> template<typename F, template<typename...> class Tuple, typename... T>
static auto apply(F&& f, Tuple<T...>& args, static Result apply(F&& f, Tuple<T...>& args)
typename enable_if<is_manipulator<F>, int>::type = 0)
-> typename get_result_type<F>::type
{ {
return f(get_ref<Range>(args)...); return f(get_ref<Range>(args)...);
} }
}; };
template<int From, int To, int... Args> template<typename Result, bool IsManipulator, int From, int To, int... Args>
struct apply_tuple_util : apply_tuple_util<From, To-1, To, Args...> struct apply_tuple_util
: apply_tuple_util<Result, IsManipulator, From, To-1, To, Args...>
{ {
}; };
template<int X, int... Args> template<typename Result, bool IsManipulator, int X, int... Args>
struct apply_tuple_util<X, X, Args...> : apply_tuple_impl<X, Args...> struct apply_tuple_util<Result, IsManipulator, X, X, Args...>
: apply_tuple_impl<Result, IsManipulator, X, Args...>
{ {
}; };
template<> template<typename Result, bool IsManipulator>
struct apply_tuple_util<1, 0> struct apply_tuple_util<Result, IsManipulator, 1, 0>
{ {
template<typename F, class Unused> template<typename F, class Unused>
static auto apply(F&& f, Unused const&) -> typename get_result_type<F>::type static Result apply(F&& f, Unused const&)
{ {
return f(); return f();
} }
...@@ -81,6 +85,7 @@ template<typename F, template<typename...> class Tuple, typename... T> ...@@ -81,6 +85,7 @@ template<typename F, template<typename...> class Tuple, typename... T>
auto apply_tuple(F&& fun, Tuple<T...>& tup) auto apply_tuple(F&& fun, Tuple<T...>& tup)
-> typename get_result_type<F>::type -> typename get_result_type<F>::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;
static constexpr size_t tup_size = sizeof...(T); static constexpr size_t tup_size = sizeof...(T);
static_assert(tup_size >= fun_args::size, static_assert(tup_size >= fun_args::size,
...@@ -88,13 +93,15 @@ auto apply_tuple(F&& fun, Tuple<T...>& tup) ...@@ -88,13 +93,15 @@ auto apply_tuple(F&& fun, Tuple<T...>& tup)
static constexpr size_t args_size = fun_args::size; static constexpr size_t args_size = fun_args::size;
static constexpr size_t from = (args_size > 0) ? tup_size - args_size : 1; static constexpr size_t from = (args_size > 0) ? tup_size - args_size : 1;
static constexpr size_t to = (args_size > 0) ? tup_size - 1 : 0; static constexpr size_t to = (args_size > 0) ? tup_size - 1 : 0;
return apply_tuple_util<from, to>::apply(std::forward<F>(fun), tup); return apply_tuple_util<result_type, is_manipulator<F>::value, from, to>
::apply(std::forward<F>(fun), 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) auto apply_tuple(F&& fun, Tuple<T...> const& tup)
-> typename get_result_type<F>::type -> typename get_result_type<F>::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;
static constexpr size_t tup_size = sizeof...(T); static constexpr size_t tup_size = sizeof...(T);
static_assert(tup_size >= fun_args::size, static_assert(tup_size >= fun_args::size,
...@@ -102,7 +109,18 @@ auto apply_tuple(F&& fun, Tuple<T...> const& tup) ...@@ -102,7 +109,18 @@ auto apply_tuple(F&& fun, Tuple<T...> const& tup)
static constexpr size_t args_size = fun_args::size; static constexpr size_t args_size = fun_args::size;
static constexpr size_t from = (args_size > 0) ? tup_size - args_size : 1; static constexpr size_t from = (args_size > 0) ? tup_size - args_size : 1;
static constexpr size_t to = (args_size > 0) ? tup_size - 1 : 0; static constexpr size_t to = (args_size > 0) ? tup_size - 1 : 0;
return apply_tuple_util<from, to>::apply(std::forward<F>(fun), tup); return apply_tuple_util<result_type, is_manipulator<F>::value, from, to>
::apply(std::forward<F>(fun), tup);
}
template<typename Result, typename F, template<typename...> class Tuple, typename... T>
Result unchecked_apply_tuple(F&& fun, Tuple<T...>& tup)
{
static constexpr size_t tup_size = sizeof...(T);
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);
} }
} } // namespace cppa::util } } // namespace cppa::util
......
...@@ -50,6 +50,12 @@ struct static_foreach_impl ...@@ -50,6 +50,12 @@ struct static_foreach_impl
return f(get<Begin>(c)) return f(get<Begin>(c))
&& static_foreach_impl<Begin+1, End, (Begin+1 > End)>::eval(c, f); && static_foreach_impl<Begin+1, End, (Begin+1 > End)>::eval(c, f);
} }
template<typename Container, typename Fun>
static inline bool eval_or(Container const& c, Fun& f)
{
return f(get<Begin>(c))
|| static_foreach_impl<Begin+1, End, (Begin+1 > End)>::eval_or(c, f);
}
}; };
template<size_t X> template<size_t X>
...@@ -59,6 +65,8 @@ struct static_foreach_impl<X, X, false> ...@@ -59,6 +65,8 @@ struct static_foreach_impl<X, X, false>
static inline void _(Container const&, Fun&) { } static inline void _(Container const&, Fun&) { }
template<typename Container, typename Fun> template<typename Container, typename Fun>
static inline bool eval(Container const&, Fun&) { return true; } static inline bool eval(Container const&, Fun&) { return true; }
template<typename Container, typename Fun>
static inline bool eval_or(Container const&, Fun&) { return true; }
}; };
template<size_t X, size_t Y> template<size_t X, size_t Y>
...@@ -68,6 +76,8 @@ struct static_foreach_impl<X, Y, true> ...@@ -68,6 +76,8 @@ struct static_foreach_impl<X, Y, true>
static inline void _(Container const&, Fun&) { } static inline void _(Container const&, Fun&) { }
template<typename Container, typename Fun> template<typename Container, typename Fun>
static inline bool eval(Container const&, Fun&) { return true; } static inline bool eval(Container const&, Fun&) { return true; }
template<typename Container, typename Fun>
static inline bool eval_or(Container const&, Fun&) { return true; }
}; };
/** /**
......
...@@ -34,7 +34,7 @@ namespace cppa { ...@@ -34,7 +34,7 @@ namespace cppa {
value_matcher::~value_matcher() { } value_matcher::~value_matcher() { }
bool dummy_matcher::operator()(any_tuple const&) bool dummy_matcher::operator()(any_tuple const&) const
{ {
return true; return true;
} }
......
This diff is collapsed.
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