Commit 4f2dd639 authored by Dominik Charousset's avatar Dominik Charousset

matches.hpp: streamlined static assertion

parent 5a7db4aa
...@@ -140,14 +140,13 @@ struct matcher<wildcard_position::in_between, Tuple, T...> { ...@@ -140,14 +140,13 @@ struct matcher<wildcard_position::in_between, Tuple, T...> {
static constexpr size_t size = sizeof...(T); static constexpr size_t size = sizeof...(T);
static constexpr size_t wc_pos = static_cast<size_t>(signed_wc_pos); static constexpr size_t wc_pos = static_cast<size_t>(signed_wc_pos);
static_assert( signed_wc_pos != -1 static_assert( signed_wc_pos > 0
&& signed_wc_pos != 0 && signed_wc_pos < (sizeof...(T) - 1),
&& signed_wc_pos != (sizeof...(T) - 1),
"illegal wildcard position"); "illegal wildcard position");
static inline bool tmatch(const Tuple& tup) { static inline bool tmatch(const Tuple& tup) {
auto tup_size = tup.size(); auto tup_size = tup.size();
if (tup_size >= size) { if (tup_size >= (size - 1)) {
auto& tarr = static_types_array<T...>::arr; auto& tarr = static_types_array<T...>::arr;
// first range [0, X1) // first range [0, X1)
auto begin = tup.begin(); auto begin = tup.begin();
...@@ -245,9 +244,14 @@ struct matcher<wildcard_position::multiple, Tuple, T...> { ...@@ -245,9 +244,14 @@ struct matcher<wildcard_position::multiple, Tuple, T...> {
auto fpush = [&](const typename Tuple::const_iterator& iter) { auto fpush = [&](const typename Tuple::const_iterator& iter) {
mv.push_back(iter.position()); mv.push_back(iter.position());
}; };
auto fcommit = [&]() { commited_size = mv.size(); }; auto fcommit = [&] {
auto frollback = [&]() { mv.resize(commited_size); }; commited_size = mv.size();
return match(tup.begin(), tup.end(), tarr.begin(), tarr.end(), };
auto frollback = [&] {
mv.resize(commited_size);
};
return match(tup.begin(), tup.end(),
tarr.begin(), tarr.end(),
fpush, fcommit, frollback); fpush, fcommit, frollback);
} }
return false; return false;
...@@ -290,7 +294,7 @@ struct match_impl_from_type_list; ...@@ -290,7 +294,7 @@ struct match_impl_from_type_list;
template<class Tuple, typename... Ts> template<class Tuple, typename... Ts>
struct match_impl_from_type_list<Tuple, util::type_list<Ts...> > { struct match_impl_from_type_list<Tuple, util::type_list<Ts...> > {
typedef match_impl<get_wildcard_position<util::type_list<Ts...> >(), typedef match_impl<get_wildcard_position<util::type_list<Ts...>>(),
Tuple, Tuple,
Ts...> Ts...>
type; type;
......
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