Commit 96871ee5 authored by Dominik Charousset's avatar Dominik Charousset

maintenance & type_list interface changes

the type_list interface changed and the class itself no longer has
any members, tl_size<>, tl_head<>, etc. must be used instead;
these "template functions" also work with any variadic template class;
this patch also changes some code parts to be more consistent with
libcppa's coding style and naming convention
parent 6614afd3
...@@ -165,9 +165,9 @@ class cow_tuple<Head, Tail...> { ...@@ -165,9 +165,9 @@ class cow_tuple<Head, Tail...> {
template<typename TypeList> template<typename TypeList>
struct cow_tuple_from_type_list; struct cow_tuple_from_type_list;
template<typename... Types> template<typename... Ts>
struct cow_tuple_from_type_list< util::type_list<Types...> > { struct cow_tuple_from_type_list< util::type_list<Ts...> > {
typedef cow_tuple<Types...> type; typedef cow_tuple<Ts...> type;
}; };
#ifdef CPPA_DOCUMENTATION #ifdef CPPA_DOCUMENTATION
...@@ -207,15 +207,15 @@ cow_tuple<Args...> make_cow_tuple(Args&&... args); ...@@ -207,15 +207,15 @@ cow_tuple<Args...> make_cow_tuple(Args&&... args);
#else #else
template<size_t N, typename... Types> template<size_t N, typename... Ts>
const typename util::at<N, Types...>::type& get(const cow_tuple<Types...>& tup) { const typename util::at<N, Ts...>::type& get(const cow_tuple<Ts...>& tup) {
typedef typename util::at<N, Types...>::type result_type; typedef typename util::at<N, Ts...>::type result_type;
return *reinterpret_cast<const result_type*>(tup.at(N)); return *reinterpret_cast<const result_type*>(tup.at(N));
} }
template<size_t N, typename... Types> template<size_t N, typename... Ts>
typename util::at<N, Types...>::type& get_ref(cow_tuple<Types...>& tup) { typename util::at<N, Ts...>::type& get_ref(cow_tuple<Ts...>& tup) {
typedef typename util::at<N, Types...>::type result_type; typedef typename util::at<N, Ts...>::type result_type;
return *reinterpret_cast<result_type*>(tup.mutable_at(N)); return *reinterpret_cast<result_type*>(tup.mutable_at(N));
} }
...@@ -234,9 +234,9 @@ make_cow_tuple(Args&&... args) { ...@@ -234,9 +234,9 @@ make_cow_tuple(Args&&... args) {
* @returns @p true if @p lhs and @p rhs are equal; otherwise @p false. * @returns @p true if @p lhs and @p rhs are equal; otherwise @p false.
* @relates cow_tuple * @relates cow_tuple
*/ */
template<typename... LhsTypes, typename... RhsTypes> template<typename... LhsTs, typename... RhsTs>
inline bool operator==(const cow_tuple<LhsTypes...>& lhs, inline bool operator==(const cow_tuple<LhsTs...>& lhs,
const cow_tuple<RhsTypes...>& rhs) { const cow_tuple<RhsTs...>& rhs) {
return util::compare_tuples(lhs, rhs); return util::compare_tuples(lhs, rhs);
} }
...@@ -247,9 +247,9 @@ inline bool operator==(const cow_tuple<LhsTypes...>& lhs, ...@@ -247,9 +247,9 @@ inline bool operator==(const cow_tuple<LhsTypes...>& lhs,
* @returns @p true if @p lhs and @p rhs are not equal; otherwise @p false. * @returns @p true if @p lhs and @p rhs are not equal; otherwise @p false.
* @relates cow_tuple * @relates cow_tuple
*/ */
template<typename... LhsTypes, typename... RhsTypes> template<typename... LhsTs, typename... RhsTs>
inline bool operator!=(const cow_tuple<LhsTypes...>& lhs, inline bool operator!=(const cow_tuple<LhsTs...>& lhs,
const cow_tuple<RhsTypes...>& rhs) { const cow_tuple<RhsTs...>& rhs) {
return !(lhs == rhs); return !(lhs == rhs);
} }
......
...@@ -49,17 +49,17 @@ ...@@ -49,17 +49,17 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
template<typename... ElementTypes> template<typename... Ts>
class decorated_tuple : public abstract_tuple { class decorated_tuple : public abstract_tuple {
typedef abstract_tuple super; typedef abstract_tuple super;
static_assert(sizeof...(ElementTypes) > 0, static_assert(sizeof...(Ts) > 0,
"decorated_tuple is not allowed to be empty"); "decorated_tuple is not allowed to be empty");
public: public:
typedef util::fixed_vector<size_t, sizeof...(ElementTypes)> vector_type; typedef util::fixed_vector<size_t, sizeof...(Ts)> vector_type;
typedef cow_ptr<abstract_tuple> cow_pointer_type; typedef cow_ptr<abstract_tuple> cow_pointer_type;
...@@ -79,7 +79,7 @@ class decorated_tuple : public abstract_tuple { ...@@ -79,7 +79,7 @@ class decorated_tuple : public abstract_tuple {
} }
virtual size_t size() const { virtual size_t size() const {
return sizeof...(ElementTypes); return sizeof...(Ts);
} }
virtual decorated_tuple* copy() const { virtual decorated_tuple* copy() const {
...@@ -97,7 +97,7 @@ class decorated_tuple : public abstract_tuple { ...@@ -97,7 +97,7 @@ class decorated_tuple : public abstract_tuple {
} }
const std::type_info* type_token() const { const std::type_info* type_token() const {
return static_type_list<ElementTypes...>::list; return static_type_list<Ts...>::list;
} }
private: private:
...@@ -111,8 +111,8 @@ class decorated_tuple : public abstract_tuple { ...@@ -111,8 +111,8 @@ class decorated_tuple : public abstract_tuple {
# ifdef CPPA_DEBUG # ifdef CPPA_DEBUG
const cow_pointer_type& ptr = m_decorated; // prevent detaching const cow_pointer_type& ptr = m_decorated; // prevent detaching
# endif # endif
CPPA_REQUIRE(ptr->size() >= sizeof...(ElementTypes)); CPPA_REQUIRE(ptr->size() >= sizeof...(Ts));
CPPA_REQUIRE(v.size() == sizeof...(ElementTypes)); CPPA_REQUIRE(v.size() == sizeof...(Ts));
CPPA_REQUIRE(*(std::max_element(v.begin(), v.end())) < ptr->size()); CPPA_REQUIRE(*(std::max_element(v.begin(), v.end())) < ptr->size());
} }
...@@ -121,10 +121,10 @@ class decorated_tuple : public abstract_tuple { ...@@ -121,10 +121,10 @@ class decorated_tuple : public abstract_tuple {
# ifdef CPPA_DEBUG # ifdef CPPA_DEBUG
const cow_pointer_type& ptr = m_decorated; // prevent detaching const cow_pointer_type& ptr = m_decorated; // prevent detaching
# endif # endif
CPPA_REQUIRE((ptr->size() - offset) >= sizeof...(ElementTypes)); CPPA_REQUIRE((ptr->size() - offset) >= sizeof...(Ts));
CPPA_REQUIRE(offset > 0); CPPA_REQUIRE(offset > 0);
size_t i = offset; size_t i = offset;
m_mapping.resize(sizeof...(ElementTypes)); m_mapping.resize(sizeof...(Ts));
std::generate(m_mapping.begin(), m_mapping.end(), [&]() {return i++;}); std::generate(m_mapping.begin(), m_mapping.end(), [&]() {return i++;});
} }
...@@ -137,9 +137,9 @@ class decorated_tuple : public abstract_tuple { ...@@ -137,9 +137,9 @@ class decorated_tuple : public abstract_tuple {
template<typename TypeList> template<typename TypeList>
struct decorated_cow_tuple_from_type_list; struct decorated_cow_tuple_from_type_list;
template<typename... Types> template<typename... Ts>
struct decorated_cow_tuple_from_type_list< util::type_list<Types...> > { struct decorated_cow_tuple_from_type_list< util::type_list<Ts...> > {
typedef decorated_tuple<Types...> type; typedef decorated_tuple<Ts...> type;
}; };
} } // namespace cppa::detail } } // namespace cppa::detail
......
...@@ -55,7 +55,7 @@ class event_based_actor_impl : public event_based_actor { ...@@ -55,7 +55,7 @@ class event_based_actor_impl : public event_based_actor {
void on_exit() { void on_exit() {
typedef typename util::get_arg_types<CleanupFun>::types arg_types; typedef typename util::get_arg_types<CleanupFun>::types arg_types;
std::integral_constant<size_t, arg_types::size> token; std::integral_constant<size_t, util::tl_size<arg_types>::value> token;
on_exit_impl(m_on_exit, token); on_exit_impl(m_on_exit, token);
} }
......
...@@ -31,26 +31,28 @@ ...@@ -31,26 +31,28 @@
#ifndef CPPA_PSEUDO_TUPLE_HPP #ifndef CPPA_PSEUDO_TUPLE_HPP
#define CPPA_PSEUDO_TUPLE_HPP #define CPPA_PSEUDO_TUPLE_HPP
#include <cstddef>
#include "cppa/util/at.hpp" #include "cppa/util/at.hpp"
namespace cppa { namespace detail { namespace cppa { namespace detail {
// tuple-like access to an array of void pointers
template<typename... T> template<typename... T>
struct pseudo_tuple { struct pseudo_tuple {
typedef void* ptr_type; typedef void* pointer;
typedef const void* const_ptr_type; typedef const void* const_pointer;
ptr_type data[sizeof...(T) > 0 ? sizeof...(T) : 1]; pointer data[sizeof...(T) > 0 ? sizeof...(T) : 1];
inline const_ptr_type at(size_t p) const { inline const_pointer at(size_t p) const {
return data[p]; return data[p];
} }
inline ptr_type mutable_at(size_t p) { inline pointer mutable_at(size_t p) {
return const_cast<ptr_type>(data[p]); return const_cast<pointer>(data[p]);
} }
inline void*& operator[](size_t p) { inline pointer& operator[](size_t p) {
return data[p]; return data[p];
} }
}; };
...@@ -67,16 +69,16 @@ struct pseudo_tuple_from_type_list<util::type_list<Ts...> > { ...@@ -67,16 +69,16 @@ struct pseudo_tuple_from_type_list<util::type_list<Ts...> > {
namespace cppa { namespace cppa {
template<size_t N, typename... Tn> template<size_t N, typename... Ts>
const typename util::at<N, Tn...>::type& get(const detail::pseudo_tuple<Tn...>& tv) { const typename util::at<N, Ts...>::type& get(const detail::pseudo_tuple<Ts...>& tv) {
static_assert(N < sizeof...(Tn), "N >= tv.size()"); static_assert(N < sizeof...(Ts), "N >= tv.size()");
return *reinterpret_cast<const typename util::at<N, Tn...>::type*>(tv.at(N)); return *reinterpret_cast<const typename util::at<N, Ts...>::type*>(tv.at(N));
} }
template<size_t N, typename... Tn> template<size_t N, typename... Ts>
typename util::at<N, Tn...>::type& get_ref(detail::pseudo_tuple<Tn...>& tv) { typename util::at<N, Ts...>::type& get_ref(detail::pseudo_tuple<Ts...>& tv) {
static_assert(N < sizeof...(Tn), "N >= tv.size()"); static_assert(N < sizeof...(Ts), "N >= tv.size()");
return *reinterpret_cast<typename util::at<N, Tn...>::type*>(tv.mutable_at(N)); return *reinterpret_cast<typename util::at<N, Ts...>::type*>(tv.mutable_at(N));
} }
} // namespace cppa } // namespace cppa
......
...@@ -427,16 +427,16 @@ mk_tdata(Args&&... args) { ...@@ -427,16 +427,16 @@ mk_tdata(Args&&... args) {
return {std::forward<Args>(args)...}; return {std::forward<Args>(args)...};
} }
template<size_t N, typename... Tn> template<size_t N, typename... Ts>
const typename util::at<N, Tn...>::type& get(const detail::tdata<Tn...>& tv) { const typename util::at<N, Ts...>::type& get(const detail::tdata<Ts...>& tv) {
static_assert(N < sizeof...(Tn), "N >= tv.size()"); static_assert(N < sizeof...(Ts), "N >= tv.size()");
return static_cast<const typename detail::tdata_upcast_helper<N, Tn...>::type&>(tv).head; return static_cast<const typename detail::tdata_upcast_helper<N, Ts...>::type&>(tv).head;
} }
template<size_t N, typename... Tn> template<size_t N, typename... Ts>
typename util::at<N, Tn...>::type& get_ref(detail::tdata<Tn...>& tv) { typename util::at<N, Ts...>::type& get_ref(detail::tdata<Ts...>& tv) {
static_assert(N < sizeof...(Tn), "N >= tv.size()"); static_assert(N < sizeof...(Ts), "N >= tv.size()");
return static_cast<typename detail::tdata_upcast_helper<N, Tn...>::type&>(tv).head; return static_cast<typename detail::tdata_upcast_helper<N, Ts...>::type&>(tv).head;
} }
} // namespace cppa } // namespace cppa
......
...@@ -42,19 +42,19 @@ ...@@ -42,19 +42,19 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
template<typename... ElementTypes> template<typename... Ts>
class tuple_vals : public abstract_tuple { class tuple_vals : public abstract_tuple {
static_assert(sizeof...(ElementTypes) > 0, static_assert(sizeof...(Ts) > 0,
"tuple_vals is not allowed to be empty"); "tuple_vals is not allowed to be empty");
typedef abstract_tuple super; typedef abstract_tuple super;
public: public:
typedef tdata<ElementTypes...> data_type; typedef tdata<Ts...> data_type;
typedef types_array<ElementTypes...> element_types; typedef types_array<Ts...> element_types;
tuple_vals(const tuple_vals&) = default; tuple_vals(const tuple_vals&) = default;
...@@ -80,7 +80,7 @@ class tuple_vals : public abstract_tuple { ...@@ -80,7 +80,7 @@ class tuple_vals : public abstract_tuple {
} }
size_t size() const { size_t size() const {
return sizeof...(ElementTypes); return sizeof...(Ts);
} }
tuple_vals* copy() const { tuple_vals* copy() const {
...@@ -112,26 +112,26 @@ class tuple_vals : public abstract_tuple { ...@@ -112,26 +112,26 @@ class tuple_vals : public abstract_tuple {
} }
const std::type_info* type_token() const { const std::type_info* type_token() const {
return detail::static_type_list<ElementTypes...>::list; return detail::static_type_list<Ts...>::list;
} }
private: private:
data_type m_data; data_type m_data;
static types_array<ElementTypes...> m_types; static types_array<Ts...> m_types;
}; };
template<typename... ElementTypes> template<typename... Ts>
types_array<ElementTypes...> tuple_vals<ElementTypes...>::m_types; types_array<Ts...> tuple_vals<Ts...>::m_types;
template<typename TypeList> template<typename TypeList>
struct tuple_vals_from_type_list; struct tuple_vals_from_type_list;
template<typename... Types> template<typename... Ts>
struct tuple_vals_from_type_list< util::type_list<Types...> > { struct tuple_vals_from_type_list< util::type_list<Ts...> > {
typedef tuple_vals<Types...> type; typedef tuple_vals<Ts...> type;
}; };
} } // namespace cppa::detail } } // namespace cppa::detail
......
...@@ -48,19 +48,19 @@ struct tuple_view_copy_helper { ...@@ -48,19 +48,19 @@ struct tuple_view_copy_helper {
} }
}; };
template<typename... ElementTypes> template<typename... Ts>
class tuple_view : public abstract_tuple { class tuple_view : public abstract_tuple {
static_assert(sizeof...(ElementTypes) > 0, static_assert(sizeof...(Ts) > 0,
"tuple_vals is not allowed to be empty"); "tuple_vals is not allowed to be empty");
typedef abstract_tuple super; typedef abstract_tuple super;
public: public:
typedef tdata<ElementTypes*...> data_type; typedef tdata<Ts*...> data_type;
typedef types_array<ElementTypes...> element_types; typedef types_array<Ts...> element_types;
tuple_view() = delete; tuple_view() = delete;
tuple_view(const tuple_view&) = delete; tuple_view(const tuple_view&) = delete;
...@@ -68,7 +68,7 @@ class tuple_view : public abstract_tuple { ...@@ -68,7 +68,7 @@ class tuple_view : public abstract_tuple {
/** /**
* @warning @p tuple_view does @b NOT takes ownership for given pointers * @warning @p tuple_view does @b NOT takes ownership for given pointers
*/ */
tuple_view(ElementTypes*... args) tuple_view(Ts*... args)
: super(tuple_impl_info::statically_typed), m_data(args...) { : super(tuple_impl_info::statically_typed), m_data(args...) {
} }
...@@ -81,13 +81,13 @@ class tuple_view : public abstract_tuple { ...@@ -81,13 +81,13 @@ class tuple_view : public abstract_tuple {
} }
size_t size() const { size_t size() const {
return sizeof...(ElementTypes); return sizeof...(Ts);
} }
abstract_tuple* copy() const { abstract_tuple* copy() const {
auto result = new tuple_vals<ElementTypes...>; auto result = new tuple_vals<Ts...>;
tuple_view_copy_helper f{result}; tuple_view_copy_helper f{result};
util::static_foreach<0, sizeof...(ElementTypes)>::_(m_data, f); util::static_foreach<0, sizeof...(Ts)>::_(m_data, f);
return result; return result;
} }
...@@ -107,19 +107,19 @@ class tuple_view : public abstract_tuple { ...@@ -107,19 +107,19 @@ class tuple_view : public abstract_tuple {
} }
const std::type_info* type_token() const { const std::type_info* type_token() const {
return detail::static_type_list<ElementTypes...>::list; return detail::static_type_list<Ts...>::list;
} }
private: private:
data_type m_data; data_type m_data;
static types_array<ElementTypes...> m_types; static types_array<Ts...> m_types;
}; };
template<typename... ElementTypes> template<typename... Ts>
types_array<ElementTypes...> tuple_view<ElementTypes...>::m_types; types_array<Ts...> tuple_view<Ts...>::m_types;
} } // namespace cppa::detail } } // namespace cppa::detail
......
...@@ -161,7 +161,7 @@ struct types_array : types_array_impl<util::tl_forall<util::type_list<T...>, ...@@ -161,7 +161,7 @@ struct types_array : types_array_impl<util::tl_forall<util::type_list<T...>,
typedef util::type_list<T...> types; typedef util::type_list<T...> types;
typedef typename util::tl_filter_not<types, is_anything>::type typedef typename util::tl_filter_not<types, is_anything>::type
filtered_types; filtered_types;
static constexpr size_t filtered_size = filtered_types::size; static constexpr size_t filtered_size = util::tl_size<filtered_types>::value;
inline bool has_values() const { return false; } inline bool has_values() const { return false; }
}; };
......
...@@ -113,16 +113,15 @@ class value_guard { ...@@ -113,16 +113,15 @@ class value_guard {
return true; return true;
} }
template<typename Head, typename Arg0, typename... Args> template<typename T0, typename Arg0, typename... Args>
static inline bool _eval(const Head& head, const tdata<>&, static inline bool _eval(const T0& head, const tdata<>&,
const Arg0& arg0, const Args&...) { const Arg0& arg0, const Args&...) {
return cmp(head, arg0); return cmp(head, arg0);
} }
template<typename Head, template<typename T0, typename T1, typename... Ts,
typename Tail0, typename... Tail,
typename Arg0, typename... Args> typename Arg0, typename... Args>
static inline bool _eval(const Head& head, const tdata<Tail0,Tail...>& tail, static inline bool _eval(const T0& head, const tdata<T1,Ts...>& tail,
const Arg0& arg0, const Args&... args) { const Arg0& arg0, const Args&... args) {
return cmp(head, arg0) && _eval(tail.head, tail.tail(), args...); return cmp(head, arg0) && _eval(tail.head, tail.tail(), args...);
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
// functions are documented in the implementation headers // functions are documented in the implementation headers
#ifndef CPPA_DOCUMENTATION #ifndef CPPA_DOCUMENTATION
#include <tuple>
#include <cstddef> #include <cstddef>
#include "cppa/util/at.hpp" #include "cppa/util/at.hpp"
...@@ -54,32 +55,56 @@ template<typename...> struct type_list; ...@@ -54,32 +55,56 @@ template<typename...> struct type_list;
template<typename...> class cow_tuple; template<typename...> class cow_tuple;
// forward declaration of get(const detail::tdata<...>&) // forward declaration of get(const detail::tdata<...>&)
template<size_t N, typename... Tn> template<size_t N, typename... Ts>
const typename util::at<N, Tn...>::type& get(const detail::tdata<Tn...>&); const typename util::at<N, Ts...>::type& get(const detail::tdata<Ts...>&);
// forward declarations of get(const tuple<...>&) // forward declarations of get(const tuple<...>&)
template<size_t N, typename... Tn> template<size_t N, typename... Ts>
const typename util::at<N, Tn...>::type& get(const cow_tuple<Tn...>&); const typename util::at<N, Ts...>::type& get(const cow_tuple<Ts...>&);
// forward declarations of get(detail::pseudo_tuple<...>&) // forward declarations of get(detail::pseudo_tuple<...>&)
template<size_t N, typename... Tn> template<size_t N, typename... Ts>
const typename util::at<N, Tn...>::type& get(const detail::pseudo_tuple<Tn...>& tv); const typename util::at<N, Ts...>::type& get(const detail::pseudo_tuple<Ts...>& tv);
// forward declarations of get(util::type_list<...>&) // forward declarations of get(util::type_list<...>&)
template<size_t N, typename... Ts> template<size_t N, typename... Ts>
typename util::at<N, Ts...>::type get(const util::type_list<Ts...>&); typename util::at<N, Ts...>::type get(const util::type_list<Ts...>&);
// forward declarations of get_ref(detail::tdata<...>&) // forward declarations of get_ref(detail::tdata<...>&)
template<size_t N, typename... Tn> template<size_t N, typename... Ts>
typename util::at<N, Tn...>::type& get_ref(detail::tdata<Tn...>&); typename util::at<N, Ts...>::type& get_ref(detail::tdata<Ts...>&);
// forward declarations of get_ref(tuple<...>&) // forward declarations of get_ref(tuple<...>&)
template<size_t N, typename... Tn> template<size_t N, typename... Ts>
typename util::at<N, Tn...>::type& get_ref(cow_tuple<Tn...>&); typename util::at<N, Ts...>::type& get_ref(cow_tuple<Ts...>&);
// forward declarations of get_ref(detail::pseudo_tuple<...>&) // forward declarations of get_ref(detail::pseudo_tuple<...>&)
template<size_t N, typename... Tn> template<size_t N, typename... Ts>
typename util::at<N, Tn...>::type& get_ref(detail::pseudo_tuple<Tn...>& tv); typename util::at<N, Ts...>::type& get_ref(detail::pseudo_tuple<Ts...>& tv);
// support get_ref access to std::tuple
template<size_t Pos, typename... Ts>
inline auto get_ref(std::tuple<Ts...>& tup) -> decltype(std::get<Pos>(tup)) {
return std::get<Pos>(tup);
}
/**
* @brief This function grants either const or non-const access to @p tup,
* depending on the cv-qualifier of @p tup.
*/
template<size_t Pos, class Tuple>
inline auto get_cv_aware(Tuple& tup) -> decltype(get_ref<Pos>(tup)) {
return get_ref<Pos>(tup);
}
/**
* @brief This function grants either const or non-const access to @p tup,
* depending on the cv-qualifier of @p tup.
*/
template<size_t Pos, class Tuple>
inline auto get_cv_aware(const Tuple& tup) -> decltype(get<Pos>(tup)) {
return get<Pos>(tup);
}
} // namespace cppa } // namespace cppa
......
...@@ -208,7 +208,7 @@ template<bool EvaluateSubResult> // default = false ...@@ -208,7 +208,7 @@ template<bool EvaluateSubResult> // default = false
struct run_case_impl { struct run_case_impl {
template<class Case, typename T> template<class Case, typename T>
static inline bool _(Case& target, std::vector<T>& vec, bool&) { static inline bool _(Case& target, std::vector<T>& vec, bool&) {
return unwind_and_call<0, Case::pattern_type::size>::_(target, vec); return unwind_and_call<0, util::tl_size<typename Case::pattern_type>::value>::_(target, vec);
} }
}; };
...@@ -217,7 +217,7 @@ struct run_case_impl<true> { ...@@ -217,7 +217,7 @@ struct run_case_impl<true> {
template<class Case, typename T> template<class Case, typename T>
static inline bool _(Case& target, std::vector<T>& vec, bool& match_returned_false) { static inline bool _(Case& target, std::vector<T>& vec, bool& match_returned_false) {
bool sub_result; bool sub_result;
if (unwind_and_call<0, Case::pattern_type::size>::_(target, sub_result, vec)) { if (unwind_and_call<0, util::tl_size<typename Case::pattern_type>::value>::_(target, sub_result, vec)) {
if (sub_result == false) { if (sub_result == false) {
match_returned_false = true; match_returned_false = true;
} }
...@@ -234,7 +234,7 @@ size_t run_case(std::vector<T>& vec, ...@@ -234,7 +234,7 @@ size_t run_case(std::vector<T>& vec,
InputIterator& pos, InputIterator& pos,
const InputIterator& end, const InputIterator& end,
Case& target) { Case& target) {
static constexpr size_t num_args = Case::pattern_type::size; static constexpr size_t num_args = util::tl_size<typename Case::pattern_type>::value;
typedef typename Case::second_type partial_fun_type; typedef typename Case::second_type partial_fun_type;
typedef typename partial_fun_type::result_type result_type; typedef typename partial_fun_type::result_type result_type;
typedef typename partial_fun_type::arg_types arg_types; typedef typename partial_fun_type::arg_types arg_types;
...@@ -275,7 +275,7 @@ class stream_matcher { ...@@ -275,7 +275,7 @@ class stream_matcher {
template<typename... Cases> template<typename... Cases>
bool operator()(match_expr<Cases...>& expr) { bool operator()(match_expr<Cases...>& expr) {
while (m_pos != m_end) { while (m_pos != m_end) {
if (!unwind_and_call<0, match_expr<Cases...>::cases_list::size>::_(m_cache, m_pos, m_end, expr)) { if (!unwind_and_call<0, util::tl_size<typename match_expr<Cases...>::cases_list>::value>::_(m_cache, m_pos, m_end, expr)) {
return false; return false;
} }
} }
......
...@@ -74,13 +74,13 @@ struct invoke_policy_impl { ...@@ -74,13 +74,13 @@ struct invoke_policy_impl {
>::type >::type
mimpl; mimpl;
util::fixed_vector<size_t, filtered_pattern::size> mv; util::fixed_vector<size_t, util::tl_size<filtered_pattern>::value> mv;
if (type_token == typeid(filtered_pattern) || mimpl::_(tup, mv)) { if (type_token == typeid(filtered_pattern) || mimpl::_(tup, mv)) {
typedef typename pseudo_tuple_from_type_list<filtered_pattern>::type typedef typename pseudo_tuple_from_type_list<filtered_pattern>::type
ttup_type; ttup_type;
ttup_type ttup; ttup_type ttup;
// if we strip const here ... // if we strip const here ...
for (size_t i = 0; i < filtered_pattern::size; ++i) { for (size_t i = 0; i < util::tl_size<filtered_pattern>::value; ++i) {
ttup[i] = const_cast<void*>(tup.at(mv[i])); ttup[i] = const_cast<void*>(tup.at(mv[i]));
} }
// ... we restore it here again // ... we restore it here again
...@@ -192,10 +192,10 @@ struct invoke_policy_impl<wildcard_position::nil, ...@@ -192,10 +192,10 @@ struct invoke_policy_impl<wildcard_position::nil,
} }
else if (timpl == detail::dynamically_typed) { else if (timpl == detail::dynamically_typed) {
auto& arr = arr_type::arr; auto& arr = arr_type::arr;
if (tup.size() != filtered_pattern::size) { if (tup.size() != util::tl_size<filtered_pattern>::value) {
return false; return false;
} }
for (size_t i = 0; i < filtered_pattern::size; ++i) { for (size_t i = 0; i < util::tl_size<filtered_pattern>::value; ++i) {
if (arr[i] != tup.type_at(i)) { if (arr[i] != tup.type_at(i)) {
return false; return false;
} }
...@@ -262,10 +262,10 @@ struct invoke_policy_impl<wildcard_position::trailing, ...@@ -262,10 +262,10 @@ struct invoke_policy_impl<wildcard_position::trailing,
} }
typedef detail::static_types_array<Ts...> arr_type; typedef detail::static_types_array<Ts...> arr_type;
auto& arr = arr_type::arr; auto& arr = arr_type::arr;
if (tup.size() < filtered_pattern::size) { if (tup.size() < util::tl_size<filtered_pattern>::value) {
return false; return false;
} }
for (size_t i = 0; i < filtered_pattern::size; ++i) { for (size_t i = 0; i < util::tl_size<filtered_pattern>::value; ++i) {
if (arr[i] != tup.type_at(i)) { if (arr[i] != tup.type_at(i)) {
return false; return false;
} }
...@@ -310,12 +310,12 @@ struct invoke_policy_impl<wildcard_position::leading, ...@@ -310,12 +310,12 @@ struct invoke_policy_impl<wildcard_position::leading,
} }
typedef detail::static_types_array<Ts...> arr_type; typedef detail::static_types_array<Ts...> arr_type;
auto& arr = arr_type::arr; auto& arr = arr_type::arr;
if (tup.size() < filtered_pattern::size) { if (tup.size() < util::tl_size<filtered_pattern>::value) {
return false; return false;
} }
size_t i = tup.size() - filtered_pattern::size; size_t i = tup.size() - util::tl_size<filtered_pattern>::value;
size_t j = 0; size_t j = 0;
while (j < filtered_pattern::size) { while (j < util::tl_size<filtered_pattern>::value) {
if (arr[i++] != tup.type_at(j++)) { if (arr[i++] != tup.type_at(j++)) {
return false; return false;
} }
...@@ -332,9 +332,9 @@ struct invoke_policy_impl<wildcard_position::leading, ...@@ -332,9 +332,9 @@ struct invoke_policy_impl<wildcard_position::leading,
if (!can_invoke(arg_types, tup)) return false; if (!can_invoke(arg_types, tup)) return false;
typedef pseudo_tuple<Ts...> ttup_type; typedef pseudo_tuple<Ts...> ttup_type;
ttup_type ttup; ttup_type ttup;
size_t i = tup.size() - filtered_pattern::size; size_t i = tup.size() - util::tl_size<filtered_pattern>::value;
size_t j = 0; size_t j = 0;
while (j < filtered_pattern::size) { while (j < util::tl_size<filtered_pattern>::value) {
ttup[j++] = const_cast<void*>(tup.at(i++)); ttup[j++] = const_cast<void*>(tup.at(i++));
} }
// ensure const-correctness // ensure const-correctness
...@@ -381,7 +381,7 @@ struct get_case_ { ...@@ -381,7 +381,7 @@ struct get_case_ {
typedef typename util::tl_pad_right< typedef typename util::tl_pad_right<
Transformers, Transformers,
filtered_pattern::size util::tl_size<filtered_pattern>::value
>::type >::type
padded_transformers; padded_transformers;
...@@ -395,7 +395,7 @@ struct get_case_ { ...@@ -395,7 +395,7 @@ struct get_case_ {
typedef typename util::tl_map_conditional< typedef typename util::tl_map_conditional<
typename util::tl_pad_left< typename util::tl_pad_left<
typename ctrait::arg_types, typename ctrait::arg_types,
filtered_pattern::size util::tl_size<filtered_pattern>::value
>::type, >::type,
std::is_lvalue_reference, std::is_lvalue_reference,
false, false,
...@@ -512,7 +512,7 @@ struct invoke_helper2 { ...@@ -512,7 +512,7 @@ struct invoke_helper2 {
//static_assert(false, "foo"); //static_assert(false, "foo");
Token token; Token token;
invoke_helper3<Data> fun{data}; invoke_helper3<Data> fun{data};
return util::static_foreach<0, Token::size> return util::static_foreach<0, util::tl_size<Token>::value>
::eval_or(token, fun, std::forward<Args>(args)...); ::eval_or(token, fun, std::forward<Args>(args)...);
} }
}; };
...@@ -531,7 +531,7 @@ struct invoke_helper { ...@@ -531,7 +531,7 @@ struct invoke_helper {
// thus, can be invoked from same data // thus, can be invoked from same data
template<class Token, typename... Args> template<class Token, typename... Args>
bool operator()(Token, Args&&... args) { bool operator()(Token, Args&&... args) {
typedef typename Token::head type_pair; typedef typename util::tl_head<Token>::type type_pair;
typedef typename type_pair::second leaf_pair; typedef typename type_pair::second leaf_pair;
if (bitfield & 0x01) { if (bitfield & 0x01) {
// next invocation step // next invocation step
...@@ -552,7 +552,7 @@ struct can_invoke_helper { ...@@ -552,7 +552,7 @@ struct can_invoke_helper {
can_invoke_helper(std::uint64_t& mbitfield) : bitfield(mbitfield), i(0) { } can_invoke_helper(std::uint64_t& mbitfield) : bitfield(mbitfield), i(0) { }
template<class Token, typename... Args> template<class Token, typename... Args>
void operator()(Token, Args&&... args) { void operator()(Token, Args&&... args) {
typedef typename Token::head type_pair; typedef typename util::tl_head<Token>::type type_pair;
typedef typename type_pair::second leaf_pair; typedef typename type_pair::second leaf_pair;
typedef invoke_policy<typename leaf_pair::pattern_type> impl; typedef invoke_policy<typename leaf_pair::pattern_type> impl;
if (impl::can_invoke(std::forward<Args>(args)...)) { if (impl::can_invoke(std::forward<Args>(args)...)) {
...@@ -647,7 +647,7 @@ class match_expr { ...@@ -647,7 +647,7 @@ class match_expr {
eval_order token; eval_order token;
std::uint64_t tmp = 0; std::uint64_t tmp = 0;
detail::can_invoke_helper fun{tmp}; detail::can_invoke_helper fun{tmp};
util::static_foreach<0, eval_order::size> util::static_foreach<0, util::tl_size<eval_order>::value>
::_(token, fun, type_token, tup); ::_(token, fun, type_token, tup);
return tmp != 0; return tmp != 0;
} }
...@@ -691,7 +691,7 @@ class match_expr { ...@@ -691,7 +691,7 @@ class match_expr {
eval_order token; eval_order token;
detail::invoke_helper<decltype(m_cases)> fun{m_cases, enabled_begin}; detail::invoke_helper<decltype(m_cases)> fun{m_cases, enabled_begin};
return util::static_foreach<0, eval_order::size> return util::static_foreach<0, util::tl_size<eval_order>::value>
::eval_or(token, ::eval_or(token,
fun, fun,
type_token, type_token,
...@@ -788,7 +788,7 @@ class match_expr { ...@@ -788,7 +788,7 @@ class match_expr {
m_cache[i].second = 0; m_cache[i].second = 0;
eval_order token; eval_order token;
detail::can_invoke_helper fun{m_cache[i].second}; detail::can_invoke_helper fun{m_cache[i].second};
util::static_foreach<0, eval_order::size> util::static_foreach<0, util::tl_size<eval_order>::value>
::_(token, fun, *type_token, value); ::_(token, fun, *type_token, value);
} }
return m_cache[i].second; return m_cache[i].second;
...@@ -807,7 +807,7 @@ class match_expr { ...@@ -807,7 +807,7 @@ class match_expr {
auto bitfield = get_cache_entry(type_token, vals); auto bitfield = get_cache_entry(type_token, vals);
eval_order token; eval_order token;
detail::invoke_helper<decltype(m_cases)> fun{m_cases, bitfield}; detail::invoke_helper<decltype(m_cases)> fun{m_cases, bitfield};
return util::static_foreach<0, eval_order::size> return util::static_foreach<0, util::tl_size<eval_order>::value>
::eval_or(token, ::eval_or(token,
fun, fun,
*type_token, *type_token,
......
...@@ -122,8 +122,10 @@ struct disjunct_rvalue_builders { ...@@ -122,8 +122,10 @@ struct disjunct_rvalue_builders {
template<class Guard, class Transformers, class Pattern> template<class Guard, class Transformers, class Pattern>
struct rvalue_builder { struct rvalue_builder {
typedef typename util::tl_back<Pattern>::type back_type;
static constexpr bool is_complete = static constexpr bool is_complete =
!std::is_same<util::arg_match_t, typename Pattern::back>::value; !std::is_same<util::arg_match_t,back_type>::value;
typedef typename util::tl_apply<Transformers, tdata>::type fun_container; typedef typename util::tl_apply<Transformers, tdata>::type fun_container;
...@@ -198,8 +200,8 @@ template<bool IsCallable, typename T> ...@@ -198,8 +200,8 @@ template<bool IsCallable, typename T>
struct pattern_type_ { struct pattern_type_ {
typedef util::get_callable_trait<T> ctrait; typedef util::get_callable_trait<T> ctrait;
typedef typename ctrait::arg_types args; typedef typename ctrait::arg_types args;
static_assert(args::size == 1, "only unary functions allowed"); static_assert(util::tl_size<args>::value == 1, "only unary functions allowed");
typedef typename util::rm_ref<typename args::head>::type type; typedef typename util::rm_ref<typename util::tl_head<args>::type>::type type;
}; };
template<typename T> template<typename T>
......
...@@ -83,7 +83,7 @@ class tpartial_function { ...@@ -83,7 +83,7 @@ class tpartial_function {
} }
result_type operator()(Args... args) const { result_type operator()(Args... args) const {
return util::apply_args<Result, ctrait_args::size, sizeof...(Args)> return util::apply_args<Result, util::tl_size<ctrait_args>::value, sizeof...(Args)>
::_(m_expr, args...); ::_(m_expr, args...);
} }
...@@ -109,7 +109,7 @@ struct get_tpartial_function<Expr, Guard, ...@@ -109,7 +109,7 @@ struct get_tpartial_function<Expr, Guard,
typedef typename util::get_callable_trait<Expr>::type ctrait; typedef typename util::get_callable_trait<Expr>::type ctrait;
typedef typename ctrait::arg_types arg_types; typedef typename ctrait::arg_types arg_types;
static_assert(arg_types::size <= sizeof...(Args), static_assert(util::tl_size<arg_types>::value <= sizeof...(Args),
"Functor takes too much arguments"); "Functor takes too much arguments");
typedef typename get_tpartial_function< typedef typename get_tpartial_function<
......
...@@ -33,16 +33,16 @@ ...@@ -33,16 +33,16 @@
namespace cppa { namespace util { namespace cppa { namespace util {
template<size_t N, typename... Tn> template<size_t N, typename... Ts>
struct at; struct at;
template<size_t N, typename T0, typename... Tn> template<size_t N, typename T0, typename... Ts>
struct at<N, T0, Tn...> { struct at<N, T0, Ts...> {
typedef typename at<N-1, Tn...>::type type; typedef typename at<N-1, Ts...>::type type;
}; };
template<typename T0, typename... Tn> template<typename T0, typename... Ts>
struct at<0, T0, Tn...> { struct at<0, T0, Ts...> {
typedef T0 type; typedef T0 type;
}; };
......
...@@ -38,10 +38,10 @@ ...@@ -38,10 +38,10 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
template<size_t N, template<typename...> class Tuple, typename... Types> template<size_t N, template<typename...> class Tuple, typename... Ts>
const typename util::at<N, Types...>::type& const typename util::at<N, Ts...>::type&
do_get(const Tuple<Types...>& t) { do_get(const Tuple<Ts...>& t) {
return ::cppa::get<N, Types...>(t); return ::cppa::get<N, Ts...>(t);
} }
template<size_t N, typename LhsTuple, typename RhsTuple> template<size_t N, typename LhsTuple, typename RhsTuple>
...@@ -63,32 +63,32 @@ struct cmp_helper<0, LhsTuple, RhsTuple> { ...@@ -63,32 +63,32 @@ struct cmp_helper<0, LhsTuple, RhsTuple> {
namespace cppa { namespace util { namespace cppa { namespace util {
template<template<typename...> class LhsTuple, typename... LhsTypes, template<template<typename...> class LhsTuple, typename... LhsTs,
template<typename...> class RhsTuple, typename... RhsTypes> template<typename...> class RhsTuple, typename... RhsTs>
bool compare_tuples(const LhsTuple<LhsTypes...>& lhs, bool compare_tuples(const LhsTuple<LhsTs...>& lhs,
const RhsTuple<RhsTypes...>& rhs) { const RhsTuple<RhsTs...>& rhs) {
static_assert(sizeof...(LhsTypes) == sizeof...(RhsTypes), static_assert(sizeof...(LhsTs) == sizeof...(RhsTs),
"could not compare tuples of different size"); "could not compare tuples of different size");
static_assert(tl_binary_forall< static_assert(tl_binary_forall<
type_list<LhsTypes...>, type_list<LhsTs...>,
type_list<RhsTypes...>, type_list<RhsTs...>,
is_comparable is_comparable
>::value, >::value,
"types of lhs are not comparable to the types of rhs"); "types of lhs are not comparable to the types of rhs");
return detail::cmp_helper<(sizeof...(LhsTypes) - 1), return detail::cmp_helper<(sizeof...(LhsTs) - 1),
LhsTuple<LhsTypes...>, LhsTuple<LhsTs...>,
RhsTuple<RhsTypes...>>::cmp(lhs, rhs); RhsTuple<RhsTs...>>::cmp(lhs, rhs);
} }
template<template<typename...> class LhsTuple, typename... LhsTypes, template<template<typename...> class LhsTuple, typename... LhsTs,
template<typename...> class RhsTuple, typename... RhsTypes> template<typename...> class RhsTuple, typename... RhsTs>
bool compare_first_elements(const LhsTuple<LhsTypes...>& lhs, bool compare_first_elements(const LhsTuple<LhsTs...>& lhs,
const RhsTuple<RhsTypes...>& rhs) { const RhsTuple<RhsTs...>& rhs) {
typedef typename tl_zip< typedef typename tl_zip<
util::type_list<LhsTypes...>, util::type_list<LhsTs...>,
util::type_list<RhsTypes...> util::type_list<RhsTs...>
>::type >::type
zipped_types; zipped_types;
...@@ -96,8 +96,8 @@ bool compare_first_elements(const LhsTuple<LhsTypes...>& lhs, ...@@ -96,8 +96,8 @@ bool compare_first_elements(const LhsTuple<LhsTypes...>& lhs,
"types of lhs are not comparable to the types of rhs"); "types of lhs are not comparable to the types of rhs");
return detail::cmp_helper<(zipped_types::size - 1), return detail::cmp_helper<(zipped_types::size - 1),
LhsTuple<LhsTypes...>, LhsTuple<LhsTs...>,
RhsTuple<RhsTypes...>>::cmp(lhs, rhs); RhsTuple<RhsTs...>>::cmp(lhs, rhs);
} }
} } // namespace cppa::util } } // namespace cppa::util
......
...@@ -38,9 +38,9 @@ namespace cppa { namespace util { ...@@ -38,9 +38,9 @@ namespace cppa { namespace util {
template<typename... BooleanConstants> template<typename... BooleanConstants>
struct conjunction; struct conjunction;
template<typename Head, typename... Tail> template<typename T0, typename... Ts>
struct conjunction<Head, Tail...> struct conjunction<T0, Ts...>
: std::integral_constant<bool, Head::value && conjunction<Tail...>::value> { : std::integral_constant<bool, T0::value && conjunction<Ts...>::value> {
}; };
template<> template<>
......
...@@ -41,8 +41,8 @@ struct element_at; ...@@ -41,8 +41,8 @@ struct element_at;
/** /**
* @brief Returns the n-th template parameter of @p C. * @brief Returns the n-th template parameter of @p C.
*/ */
template<size_t N, template<typename...> class C, typename... Tn> template<size_t N, template<typename...> class C, typename... Ts>
struct element_at<N, C<Tn...>> : at<N, Tn...> { struct element_at<N, C<Ts...>> : at<N, Ts...> {
}; };
} } // namespace cppa::util } } // namespace cppa::util
......
...@@ -59,47 +59,104 @@ namespace cppa { namespace util { ...@@ -59,47 +59,104 @@ namespace cppa { namespace util {
* @{ * @{
*/ */
template<typename... Types> struct type_list; /**
* @brief A list of types.
*/
template<typename... Ts>
struct type_list { };
template<> /**
struct type_list<> { * @brief Denotes the empty list.
typedef void_type head; */
typedef void_type back; typedef type_list<> empty_type_list;
typedef type_list<> tail;
static const size_t size = 0; template<typename T>
struct is_type_list {
static constexpr bool value = false;
}; };
template<typename... Ts>
struct is_type_list<type_list<Ts...> > {
static constexpr bool value = true;
};
// T head(type_list)
/** /**
* @brief A list of types. * @brief Gets the first element of @p List.
*/
template<class List>
struct tl_head;
template<template<typename...> class List>
struct tl_head<List<>> {
typedef empty_type_list type;
};
template<template<typename...> class List, typename T0, typename... Ts>
struct tl_head<List<T0,Ts...>> {
typedef T0 type;
};
// type_list tail(type_list)
/**
* @brief Gets the tail of @p List.
*/ */
template<typename Head, typename... Tail> template<class List>
struct type_list<Head, Tail...> { struct tl_tail;
typedef Head head; template<template<typename...> class List>
struct tl_tail<List<>> {
typedef List<> type;
};
template<template<typename...> class List, typename T0, typename... Ts>
struct tl_tail<List<T0,Ts...>> {
typedef List<Ts...> type;
};
typedef type_list<Tail...> tail;
typedef typename if_else_c<sizeof...(Tail) == 0, // size_t size(type_list)
Head,
wrapped<typename tail::back> >::type
back;
static const size_t size = sizeof...(Tail) + 1; /**
* @brief Gets the number of template parameters of @p List.
*/
template<class List>
struct tl_size;
template<template<typename...> class List, typename... Ts>
struct tl_size<List<Ts...>> {
static constexpr size_t value = sizeof...(Ts);
}; };
typedef type_list<> empty_type_list; // T back(type_list)
template<typename T> /**
struct is_type_list { * @brief Gets the last element in @p List.
static constexpr bool value = false; */
template<class List>
struct tl_back;
template<template<typename...> class List>
struct tl_back<List<>> {
typedef void_type type;
}; };
template<typename... Ts> template<template<typename...> class List, typename T0>
struct is_type_list<type_list<Ts...> > { struct tl_back<List<T0>> {
static constexpr bool value = true; typedef T0 type;
}; };
template<template<typename...> class List, typename T0, typename T1, typename... Ts>
struct tl_back<List<T0,T1,Ts...>> {
// remaining arguments are forwarded as type_list to prevent
// recursive instantiation of List class
typedef typename tl_back<type_list<T1,Ts...>>::type type;
};
// bool empty(type_list) // bool empty(type_list)
/** /**
...@@ -107,7 +164,7 @@ struct is_type_list<type_list<Ts...> > { ...@@ -107,7 +164,7 @@ struct is_type_list<type_list<Ts...> > {
*/ */
template<class List> template<class List>
struct tl_empty { struct tl_empty {
static constexpr bool value = std::is_same<empty_type_list, List>::value; static constexpr bool value = std::is_same<empty_type_list,List>::value;
}; };
// list slice(size_t, size_t) // list slice(size_t, size_t)
...@@ -119,7 +176,7 @@ struct tl_slice_impl { ...@@ -119,7 +176,7 @@ struct tl_slice_impl {
LeftOffset - 1, LeftOffset - 1,
Remaining, Remaining,
PadType, PadType,
typename List::tail, typename tl_tail<List>::type,
T... T...
>::type >::type
type; type;
...@@ -131,8 +188,9 @@ struct tl_slice_impl<0, Remaining, PadType, List, T...> { ...@@ -131,8 +188,9 @@ struct tl_slice_impl<0, Remaining, PadType, List, T...> {
0, 0,
Remaining - 1, Remaining - 1,
PadType, PadType,
typename List::tail, typename tl_tail<List>::type,
T..., typename List::head T...,
typename tl_head<List>::type
>::type >::type
type; type;
}; };
...@@ -180,7 +238,7 @@ struct tl_slice_<List, ListSize, 0, ListSize, PadType> { ...@@ -180,7 +238,7 @@ struct tl_slice_<List, ListSize, 0, ListSize, PadType> {
template<class List, size_t First, size_t Last> template<class List, size_t First, size_t Last>
struct tl_slice { struct tl_slice {
static_assert(First <= Last, "First > Last"); static_assert(First <= Last, "First > Last");
typedef typename tl_slice_<List, List::size, First, Last>::type type; typedef typename tl_slice_<List, tl_size<List>::value, First, Last>::type type;
}; };
/** /**
...@@ -206,8 +264,11 @@ struct tl_zip_impl<type_list<LhsElements...>, type_list<RhsElements...>, Fun> { ...@@ -206,8 +264,11 @@ struct tl_zip_impl<type_list<LhsElements...>, type_list<RhsElements...>, Fun> {
template<class ListA, class ListB, template<class ListA, class ListB,
template<typename, typename> class Fun = to_type_pair> template<typename, typename> class Fun = to_type_pair>
struct tl_zip { struct tl_zip {
static constexpr size_t result_size = (ListA::size < ListB::size) ? ListA::size
: ListB::size; static constexpr size_t sizea = tl_size<ListA>::value;
static constexpr size_t sizeb = tl_size<ListB>::value;
static constexpr size_t result_size = (sizea < sizeb) ? sizea : sizeb;
typedef typename tl_zip_impl< typedef typename tl_zip_impl<
typename tl_slice<ListA, 0, result_size>::type, typename tl_slice<ListA, 0, result_size>::type,
...@@ -223,19 +284,19 @@ template<class ListA, ...@@ -223,19 +284,19 @@ template<class ListA,
typename PadB = void_type, typename PadB = void_type,
template<typename, typename> class Fun = to_type_pair> template<typename, typename> class Fun = to_type_pair>
struct tl_zip_all { struct tl_zip_all {
static constexpr size_t result_size = (ListA::size > ListB::size) ? ListA::size static constexpr size_t result_size = (tl_size<ListA>::value > tl_size<ListB>::value) ? tl_size<ListA>::value
: ListB::size; : tl_size<ListB>::value;
typedef typename tl_zip_impl< typedef typename tl_zip_impl<
typename tl_slice_< typename tl_slice_<
ListA, ListA,
ListA::size, tl_size<ListA>::value,
0, 0,
result_size result_size
>::type, >::type,
typename tl_slice_< typename tl_slice_<
ListB, ListB,
ListB::size, tl_size<ListB>::value,
0, 0,
result_size result_size
>::type, >::type,
...@@ -260,7 +321,7 @@ struct tl_zip_with_index_impl; ...@@ -260,7 +321,7 @@ struct tl_zip_with_index_impl;
template<class List, size_t Pos, size_t... Range> template<class List, size_t Pos, size_t... Range>
struct tl_zip_with_index_impl<false, List, Pos, Range...> struct tl_zip_with_index_impl<false, List, Pos, Range...>
: tl_zip_with_index_impl<List::size == (Pos + 1), List, (Pos + 1), Range..., Pos> { : tl_zip_with_index_impl<tl_size<List>::value == (Pos + 1), List, (Pos + 1), Range..., Pos> {
}; };
template<typename... Ts, size_t Pos, size_t... Range> template<typename... Ts, size_t Pos, size_t... Range>
...@@ -318,12 +379,12 @@ struct tl_find_impl<empty_type_list, Predicate, Pos> { ...@@ -318,12 +379,12 @@ struct tl_find_impl<empty_type_list, Predicate, Pos> {
}; };
template<template<typename> class Predicate, int Pos, template<template<typename> class Predicate, int Pos,
typename Head, typename... Tail> typename T0, typename... Ts>
struct tl_find_impl<type_list<Head, Tail...>, Predicate, Pos> { struct tl_find_impl<type_list<T0, Ts...>, Predicate, Pos> {
static constexpr int value = static constexpr int value =
Predicate<Head>::value Predicate<T0>::value
? Pos ? Pos
: tl_find_impl<type_list<Tail...>, Predicate, Pos+1>::value; : tl_find_impl<type_list<Ts...>, Predicate, Pos+1>::value;
}; };
/** /**
...@@ -356,8 +417,8 @@ struct tl_find_if { ...@@ -356,8 +417,8 @@ struct tl_find_if {
template<class List, template<typename> class Predicate> template<class List, template<typename> class Predicate>
struct tl_forall { struct tl_forall {
static constexpr bool value = static constexpr bool value =
Predicate<typename List::head>::value Predicate<typename tl_head<List>::type>::value
&& tl_forall<typename List::tail, Predicate>::value; && tl_forall<typename tl_tail<List>::type, Predicate>::value;
}; };
template<template<typename> class Predicate> template<template<typename> class Predicate>
...@@ -368,10 +429,10 @@ struct tl_forall<empty_type_list, Predicate> { ...@@ -368,10 +429,10 @@ struct tl_forall<empty_type_list, Predicate> {
template<class ListA, class ListB, template<typename, typename> class Predicate> template<class ListA, class ListB, template<typename, typename> class Predicate>
struct tl_forall2_impl { struct tl_forall2_impl {
static constexpr bool value = static constexpr bool value =
Predicate<typename ListA::head, typename ListB::head>::value Predicate<typename tl_head<ListA>::type, typename tl_head<ListB>::type>::value
&& tl_forall2_impl< && tl_forall2_impl<
typename ListA::tail, typename tl_tail<ListA>::type,
typename ListB::tail, typename tl_tail<ListB>::type,
Predicate Predicate
>::value; >::value;
}; };
...@@ -388,7 +449,7 @@ struct tl_forall2_impl<empty_type_list, empty_type_list, Predicate> { ...@@ -388,7 +449,7 @@ struct tl_forall2_impl<empty_type_list, empty_type_list, Predicate> {
template<class ListA, class ListB, template<typename, typename> class Predicate> template<class ListA, class ListB, template<typename, typename> class Predicate>
struct tl_binary_forall { struct tl_binary_forall {
static constexpr bool value = static constexpr bool value =
ListA::size == ListB::size tl_size<ListA>::value == tl_size<ListB>::value
&& tl_forall2_impl<ListA, ListB, Predicate>::value; && tl_forall2_impl<ListA, ListB, Predicate>::value;
}; };
...@@ -398,8 +459,8 @@ struct tl_binary_forall { ...@@ -398,8 +459,8 @@ struct tl_binary_forall {
template<class List, template<typename> class Predicate> template<class List, template<typename> class Predicate>
struct tl_exists { struct tl_exists {
static constexpr bool value = static constexpr bool value =
Predicate<typename List::head>::value Predicate<typename tl_head<List>::type>::value
|| tl_exists<typename List::tail, Predicate>::value; || tl_exists<typename tl_tail<List>::type, Predicate>::value;
}; };
template<template<typename> class Predicate> template<template<typename> class Predicate>
...@@ -415,8 +476,8 @@ struct tl_exists<empty_type_list, Predicate> { ...@@ -415,8 +476,8 @@ struct tl_exists<empty_type_list, Predicate> {
*/ */
template<class List, template<typename> class Predicate> template<class List, template<typename> class Predicate>
struct tl_count { struct tl_count {
static constexpr size_t value = (Predicate<typename List::head>::value ? 1 : 0) static constexpr size_t value = (Predicate<typename tl_head<List>::type>::value ? 1 : 0)
+ tl_count<typename List::tail, Predicate>::value; + tl_count<typename tl_tail<List>::type, Predicate>::value;
}; };
template<template<typename> class Predicate> template<template<typename> class Predicate>
...@@ -431,8 +492,8 @@ struct tl_count<empty_type_list, Predicate> { ...@@ -431,8 +492,8 @@ struct tl_count<empty_type_list, Predicate> {
*/ */
template<class List, template<typename> class Predicate> template<class List, template<typename> class Predicate>
struct tl_count_not { struct tl_count_not {
static constexpr size_t value = (Predicate<typename List::head>::value ? 0 : 1) static constexpr size_t value = (Predicate<typename tl_head<List>::type>::value ? 0 : 1)
+ tl_count_not<typename List::tail, Predicate>::value; + tl_count_not<typename tl_tail<List>::type, Predicate>::value;
}; };
template<template<typename> class Predicate> template<template<typename> class Predicate>
...@@ -445,12 +506,12 @@ struct tl_count_not<empty_type_list, Predicate> { ...@@ -445,12 +506,12 @@ struct tl_count_not<empty_type_list, Predicate> {
/** /**
* @brief Tests whether a predicate holds for all elements of a zipped list. * @brief Tests whether a predicate holds for all elements of a zipped list.
*/ */
template<class ZippedList, template<typename, typename> class Predicate> template<class List, template<typename, typename> class Predicate>
struct tl_zipped_forall { struct tl_zipped_forall {
typedef typename ZippedList::head head; typedef typename tl_head<List>::type head;
static constexpr bool value = static constexpr bool value =
Predicate<typename head::first, typename head::second>::value Predicate<typename head::first, typename head::second>::value
&& tl_zipped_forall<typename ZippedList::tail, Predicate>::value; && tl_zipped_forall<typename tl_tail<List>::type, Predicate>::value;
}; };
template<template<typename, typename> class Predicate> template<template<typename, typename> class Predicate>
...@@ -464,9 +525,9 @@ struct tl_concat_impl; ...@@ -464,9 +525,9 @@ struct tl_concat_impl;
/** /**
* @brief Concatenates two lists. * @brief Concatenates two lists.
*/ */
template<typename... ListATypes, typename... ListBTypes> template<typename... LhsTs, typename... RhsTs>
struct tl_concat_impl<type_list<ListATypes...>, type_list<ListBTypes...> > { struct tl_concat_impl<type_list<LhsTs...>, type_list<RhsTs...> > {
typedef type_list<ListATypes..., ListBTypes...> type; typedef type_list<LhsTs..., RhsTs...> type;
}; };
// static list concat(list, list) // static list concat(list, list)
...@@ -499,9 +560,9 @@ struct tl_push_back; ...@@ -499,9 +560,9 @@ struct tl_push_back;
/** /**
* @brief Appends @p What to given list. * @brief Appends @p What to given list.
*/ */
template<typename... ListTypes, typename What> template<typename... ListTs, typename What>
struct tl_push_back<type_list<ListTypes...>, What> { struct tl_push_back<type_list<ListTs...>, What> {
typedef type_list<ListTypes..., What> type; typedef type_list<ListTs..., What> type;
}; };
template<class List, typename What> template<class List, typename What>
...@@ -510,9 +571,9 @@ struct tl_push_front; ...@@ -510,9 +571,9 @@ struct tl_push_front;
/** /**
* @brief Appends @p What to given list. * @brief Appends @p What to given list.
*/ */
template<typename... ListTypes, typename What> template<typename... ListTs, typename What>
struct tl_push_front<type_list<ListTypes...>, What> { struct tl_push_front<type_list<ListTs...>, What> {
typedef type_list<What, ListTypes...> type; typedef type_list<What, ListTs...> type;
}; };
// list map(list, trait) // list map(list, trait)
...@@ -556,13 +617,13 @@ struct tl_map_conditional { ...@@ -556,13 +617,13 @@ struct tl_map_conditional {
typedef typename tl_concat< typedef typename tl_concat<
type_list< type_list<
typename std::conditional< typename std::conditional<
Trait<typename List::head>::value == TraitResult, Trait<typename tl_head<List>::type>::value == TraitResult,
typename tl_apply_all<typename List::head, Funs...>::type, typename tl_apply_all<typename tl_head<List>::type, Funs...>::type,
typename List::head typename tl_head<List>::type
>::type >::type
>, >,
typename tl_map_conditional< typename tl_map_conditional<
typename List::tail, typename tl_tail<List>::type,
Trait, Trait,
TraitResult, TraitResult,
Funs... Funs...
...@@ -620,7 +681,7 @@ struct tl_zipped_map<type_list<T...>, Fun> { ...@@ -620,7 +681,7 @@ struct tl_zipped_map<type_list<T...>, Fun> {
*/ */
template<class List> template<class List>
struct tl_pop_back { struct tl_pop_back {
typedef typename tl_slice<List, 0, List::size - 1>::type type; typedef typename tl_slice<List, 0, tl_size<List>::value - 1>::type type;
}; };
template<> template<>
...@@ -652,7 +713,7 @@ struct tl_at; ...@@ -652,7 +713,7 @@ struct tl_at;
*/ */
template<size_t N, typename... E> template<size_t N, typename... E>
struct tl_at<type_list<E...>, N> { struct tl_at<type_list<E...>, N> {
static_assert(N < sizeof...(E), "N >= List::size"); static_assert(N < sizeof...(E), "N >= tl_size<List>::value");
typedef typename tl_at_impl<N, E...>::type type; typedef typename tl_at_impl<N, E...>::type type;
}; };
...@@ -754,12 +815,12 @@ struct tl_distinct; ...@@ -754,12 +815,12 @@ struct tl_distinct;
template<> template<>
struct tl_distinct<empty_type_list> { typedef empty_type_list type; }; struct tl_distinct<empty_type_list> { typedef empty_type_list type; };
template<typename Head, typename... Tail> template<typename T0, typename... Ts>
struct tl_distinct<type_list<Head, Tail...> > { struct tl_distinct<type_list<T0, Ts...> > {
typedef typename tl_concat< typedef typename tl_concat<
type_list<Head>, type_list<T0>,
typename tl_distinct< typename tl_distinct<
typename tl_filter_type<type_list<Tail...>, Head>::type typename tl_filter_type<type_list<Ts...>, T0>::type
>::type >::type
>::type >::type
type; type;
...@@ -799,7 +860,7 @@ struct tl_pad_right_impl<List, true, OldSize, NewSize, FillType> { ...@@ -799,7 +860,7 @@ struct tl_pad_right_impl<List, true, OldSize, NewSize, FillType> {
template<class List, size_t NewSize, typename FillType = void_type> template<class List, size_t NewSize, typename FillType = void_type>
struct tl_pad_right { struct tl_pad_right {
typedef typename tl_pad_right_impl< typedef typename tl_pad_right_impl<
List, (List::size < NewSize), List::size, NewSize, FillType List, (tl_size<List>::value < NewSize), tl_size<List>::value, NewSize, FillType
>::type >::type
type; type;
}; };
...@@ -828,10 +889,11 @@ struct tl_pad_left_impl<List, Size, Size, FillType> { ...@@ -828,10 +889,11 @@ struct tl_pad_left_impl<List, Size, Size, FillType> {
*/ */
template<class List, size_t NewSize, typename FillType = void_type> template<class List, size_t NewSize, typename FillType = void_type>
struct tl_pad_left { struct tl_pad_left {
//static_assert(NewSize >= List::size, "List too big"); static constexpr size_t list_size = tl_size<List>::value;
//static_assert(NewSize >= tl_size<List>::value, "List too big");
typedef typename tl_pad_left_impl< typedef typename tl_pad_left_impl<
List, List,
List::size, (List::size > NewSize) ? List::size : NewSize, list_size, (list_size > NewSize) ? list_size : NewSize,
FillType FillType
>::type >::type
type; type;
...@@ -850,7 +912,7 @@ struct tl_is_zipped { ...@@ -850,7 +912,7 @@ struct tl_is_zipped {
template<class List, typename What = void_type> template<class List, typename What = void_type>
struct tl_trim { struct tl_trim {
typedef typename util::if_else< typedef typename util::if_else<
std::is_same<typename List::back, What>, std::is_same<typename tl_back<List>::type, What>,
typename tl_trim<typename tl_pop_back<List>::type, What>::type, typename tl_trim<typename tl_pop_back<List>::type, What>::type,
util::wrapped<List> util::wrapped<List>
>::type >::type
...@@ -879,10 +941,10 @@ struct tl_group_by_impl_step<false, What, List> { ...@@ -879,10 +941,10 @@ struct tl_group_by_impl_step<false, What, List> {
template<class In, class Out, template<typename, typename> class Predicate> template<class In, class Out, template<typename, typename> class Predicate>
struct tl_group_by_impl { struct tl_group_by_impl {
typedef typename Out::back last_group; typedef typename tl_back<Out>::type last_group;
typedef typename tl_group_by_impl_step< typedef typename tl_group_by_impl_step<
Predicate<typename In::head, typename last_group::back>::value, Predicate<typename tl_head<In>::type, typename tl_back<last_group>::type>::value,
typename In::head, typename tl_head<In>::type,
last_group last_group
>::type >::type
suffix; suffix;
...@@ -890,18 +952,18 @@ struct tl_group_by_impl { ...@@ -890,18 +952,18 @@ struct tl_group_by_impl {
typedef typename tl_concat<prefix, suffix>::type new_out; typedef typename tl_concat<prefix, suffix>::type new_out;
typedef typename tl_group_by_impl< typedef typename tl_group_by_impl<
typename In::tail, typename tl_tail<In>::type,
new_out, new_out,
Predicate Predicate
>::type >::type
type; type;
}; };
template<template<typename, typename> class Predicate, typename Head, typename... Tail> template<template<typename, typename> class Predicate, typename T0, typename... Ts>
struct tl_group_by_impl<type_list<Head, Tail...>, empty_type_list, Predicate> { struct tl_group_by_impl<type_list<T0, Ts...>, empty_type_list, Predicate> {
typedef typename tl_group_by_impl< typedef typename tl_group_by_impl<
type_list<Tail...>, type_list<Ts...>,
type_list<type_list<Head> >, type_list<type_list<T0> >,
Predicate Predicate
>::type >::type
type; type;
......
...@@ -59,9 +59,9 @@ template<typename Types> ...@@ -59,9 +59,9 @@ template<typename Types>
constexpr wildcard_position get_wildcard_position() { constexpr wildcard_position get_wildcard_position() {
return util::tl_exists<Types, is_anything>::value return util::tl_exists<Types, is_anything>::value
? ((util::tl_count<Types, is_anything>::value == 1) ? ((util::tl_count<Types, is_anything>::value == 1)
? (std::is_same<typename Types::head, anything>::value ? (std::is_same<typename util::tl_head<Types>::type, anything>::value
? wildcard_position::leading ? wildcard_position::leading
: (std::is_same<typename Types::back, anything>::value : (std::is_same<typename util::tl_back<Types>::type, anything>::value
? wildcard_position::trailing ? wildcard_position::trailing
: wildcard_position::in_between)) : wildcard_position::in_between))
: wildcard_position::multiple) : wildcard_position::multiple)
......
...@@ -51,6 +51,7 @@ void event_based_actor::dequeue_response(behavior&, message_id_t) { ...@@ -51,6 +51,7 @@ void event_based_actor::dequeue_response(behavior&, message_id_t) {
} }
resume_result event_based_actor::resume(util::fiber*) { resume_result event_based_actor::resume(util::fiber*) {
CPPA_REQUIRE(m_state.load() == abstract_scheduled_actor::ready);
scoped_self_setter sss{this}; scoped_self_setter sss{this};
auto done_cb = [&]() { auto done_cb = [&]() {
m_state.store(abstract_scheduled_actor::done); m_state.store(abstract_scheduled_actor::done);
......
...@@ -26,16 +26,16 @@ int main() { ...@@ -26,16 +26,16 @@ int main() {
CPPA_CHECK((is_same<float, element_at<1, l1>::type>::value)); CPPA_CHECK((is_same<float, element_at<1, l1>::type>::value));
CPPA_CHECK((is_same<std::string, element_at<2, l1>::type>::value)); CPPA_CHECK((is_same<std::string, element_at<2, l1>::type>::value));
CPPA_CHECK(l1::size == 3); CPPA_CHECK(tl_size<l1>::value == 3);
CPPA_CHECK(l1::size == r1::size); CPPA_CHECK(tl_size<l1>::value == tl_size<r1>::value);
CPPA_CHECK((is_same<element_at<0, l1>::type, element_at<2, r1>::type>::value)); CPPA_CHECK((is_same<element_at<0, l1>::type, element_at<2, r1>::type>::value));
CPPA_CHECK((is_same<element_at<1, l1>::type, element_at<1, r1>::type>::value)); CPPA_CHECK((is_same<element_at<1, l1>::type, element_at<1, r1>::type>::value));
CPPA_CHECK((is_same<element_at<2, l1>::type, element_at<0, r1>::type>::value)); CPPA_CHECK((is_same<element_at<2, l1>::type, element_at<0, r1>::type>::value));
typedef tl_concat<type_list<int>, l1>::type l2; typedef tl_concat<type_list<int>, l1>::type l2;
CPPA_CHECK((is_same<int, l2::head>::value)); CPPA_CHECK((is_same<int, tl_head<l2>::type>::value));
CPPA_CHECK((is_same<l1, l2::tail>::value)); CPPA_CHECK((is_same<l1, tl_tail<l2>::type>::value));
return CPPA_TEST_RESULT; return CPPA_TEST_RESULT;
......
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