Commit cc45117f authored by Dominik Charousset's avatar Dominik Charousset

maintenance

parent 7e1b6857
......@@ -170,7 +170,6 @@ nobase_library_include_HEADERS = \
cppa/tuple_view.hpp \
cppa/uniform_type_info.hpp \
cppa/util/abstract_uniform_type_info.hpp \
cppa/util/a_matches_b.hpp \
cppa/util/any_tuple_iterator.hpp \
cppa/util/apply.hpp \
cppa/util/arg_match_t.hpp \
......@@ -188,7 +187,6 @@ nobase_library_include_HEADERS = \
cppa/util/element_at.hpp \
cppa/util/enable_if.hpp \
cppa/util/eval_first_n.hpp \
cppa/util/eval_type_list.hpp \
cppa/util/eval_type_lists.hpp \
cppa/util/fiber.hpp \
cppa/util/filter_type_list.hpp \
......@@ -205,21 +203,19 @@ nobase_library_include_HEADERS = \
cppa/util/is_legal_tuple_type.hpp \
cppa/util/is_one_of.hpp \
cppa/util/is_primitive.hpp \
cppa/util/pop_back.hpp \
cppa/util/producer_consumer_list.hpp \
cppa/util/pt_dispatch.hpp \
cppa/util/pt_token.hpp \
cppa/util/remove_const_reference.hpp \
cppa/util/replace_type.hpp \
cppa/util/reverse_type_list.hpp \
cppa/util/ripemd_160.hpp \
cppa/util/rm_ref.hpp \
cppa/util/shared_lock_guard.hpp \
cppa/util/shared_spinlock.hpp \
cppa/util/single_reader_queue.hpp \
cppa/util/singly_linked_list.hpp \
cppa/util/type_list_apply.hpp \
cppa/util/type_list.hpp \
cppa/util/type_pair.hpp \
cppa/util/upgrade_lock_guard.hpp \
cppa/util/void_type.hpp \
cppa/util/wrapped.hpp
......
......@@ -3,7 +3,6 @@ cppa/tuple.hpp
unit_testing/main.cpp
cppa/util/void_type.hpp
cppa/util/type_list.hpp
cppa/util/a_matches_b.hpp
cppa/util.hpp
cppa/util/is_one_of.hpp
cppa/util/conjunction.hpp
......@@ -28,10 +27,8 @@ cppa/util/concat_type_lists.hpp
cppa/util/filter_type_list.hpp
cppa/util/is_comparable.hpp
cppa/util/callable_trait.hpp
cppa/util/reverse_type_list.hpp
unit_testing/test__type_list.cpp
cppa/util/remove_const_reference.hpp
cppa/util/type_list_apply.hpp
cppa/util/eval_type_lists.hpp
cppa/util/compare_tuples.hpp
cppa/get.hpp
......@@ -138,7 +135,6 @@ cppa/from_string.hpp
cppa/util/at.hpp
cppa/util/element_at.hpp
cppa/util/if_else.hpp
cppa/util/pop_back.hpp
cppa/util/pt_dispatch.hpp
cppa/detail/get_behavior.hpp
unit_testing/test__ripemd_160.cpp
......@@ -258,3 +254,4 @@ cppa/util/producer_consumer_list.hpp
cppa/util/arg_match_t.hpp
cppa/detail/types_array.hpp
cppa/util/is_builtin.hpp
cppa/util/type_pair.hpp
......@@ -57,31 +57,31 @@ struct boxed<anything>
template<typename T>
struct is_boxed
{
static const bool value = false;
static constexpr bool value = false;
};
template<typename T>
struct is_boxed< util::wrapped<T> >
{
static const bool value = true;
static constexpr bool value = true;
};
template<typename T>
struct is_boxed<util::wrapped<T>()>
{
static const bool value = true;
static constexpr bool value = true;
};
template<typename T>
struct is_boxed<util::wrapped<T>(&)()>
{
static const bool value = true;
static constexpr bool value = true;
};
template<typename T>
struct is_boxed<util::wrapped<T>(*)()>
{
static const bool value = true;
static constexpr bool value = true;
};
} } // namespace cppa::detail
......
......@@ -72,7 +72,7 @@ class is_stl_compliant_list
public:
static const bool value = util::is_iterable<T>::value
static constexpr bool value = util::is_iterable<T>::value
&& std::is_same<bool, result_type>::value;
};
......@@ -99,7 +99,7 @@ class is_stl_compliant_map
public:
static const bool value = util::is_iterable<T>::value
static constexpr bool value = util::is_iterable<T>::value
&& std::is_same<bool, result_type>::value;
};
......@@ -111,7 +111,7 @@ class default_uniform_type_info_impl : public util::abstract_uniform_type_info<T
template<typename X>
struct is_invalid
{
static const bool value = !util::is_primitive<X>::value
static constexpr bool value = !util::is_primitive<X>::value
&& !is_stl_compliant_map<X>::value
&& !is_stl_compliant_list<X>::value;
};
......
......@@ -64,8 +64,8 @@ class ftor_behavior<true, true, F, Args...> : public scheduled_actor
F m_fun;
typedef typename tdata_from_type_list<
typename util::type_list_apply<util::type_list<Args...>,
implicit_conversions>::type>::type
typename util::tl_apply<util::type_list<Args...>,
implicit_conversions>::type>::type
tdata_type;
tdata_type m_args;
......@@ -103,8 +103,8 @@ class ftor_behavior<false, true, F, Args...> : public scheduled_actor
F m_fun;
typedef typename tdata_from_type_list<
typename util::type_list_apply<util::type_list<Args...>,
implicit_conversions>::type>::type
typename util::tl_apply<util::type_list<Args...>,
implicit_conversions>::type>::type
tdata_type;
tdata_type m_args;
......
......@@ -39,10 +39,10 @@
namespace cppa { namespace detail {
template<typename T>
struct is_pair { static const bool value = false; };
struct is_pair { static constexpr bool value = false; };
template<typename First, typename Second>
struct is_pair< std::pair<First, Second> > { static const bool value = true; };
struct is_pair< std::pair<First, Second> > { static constexpr bool value = true; };
template<typename T, bool IsPair, bool IsPrimitive>
struct map_member_util;
......
......@@ -46,9 +46,9 @@ struct serialize_tuple
template<typename T>
inline static void _(serializer& s, T const* tup)
{
s << uniform_typeid<typename List::head_type>()->name()
<< *reinterpret_cast<const typename List::head_type*>(tup->at(Pos));
serialize_tuple<typename List::tail_type, Pos + 1>::_(s, tup);
s << uniform_typeid<typename List::head>()->name()
<< *reinterpret_cast<const typename List::head*>(tup->at(Pos));
serialize_tuple<typename List::tail, Pos + 1>::_(s, tup);
}
};
......
......@@ -39,7 +39,6 @@
#include "cppa/util/wrapped.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/arg_match_t.hpp"
#include "cppa/util/filter_type_list.hpp"
#include "cppa/detail/abstract_tuple.hpp"
......
......@@ -36,6 +36,7 @@
#include "cppa/util/type_list.hpp"
#include "cppa/detail/tdata.hpp"
#include "cppa/detail/types_array.hpp"
#include "cppa/detail/abstract_tuple.hpp"
#include "cppa/detail/serialize_tuple.hpp"
......@@ -49,11 +50,11 @@ class tuple_vals : public abstract_tuple
typedef tdata<ElementTypes...> data_type;
typedef util::type_list<ElementTypes...> element_types;
typedef types_array<ElementTypes...> element_types;
data_type m_data;
element_types m_types;
static types_array<ElementTypes...> m_types;
template<typename... Types>
void* tdata_mutable_at(tdata<Types...>& d, size_t pos)
......@@ -101,7 +102,7 @@ class tuple_vals : public abstract_tuple
uniform_type_info const& utype_info_at(size_t pos) const
{
return m_types.at(pos);
return *(m_types[pos]);
}
bool equals(abstract_tuple const& other) const
......@@ -117,6 +118,9 @@ class tuple_vals : public abstract_tuple
};
template<typename... ElementTypes>
types_array<ElementTypes...> tuple_vals<ElementTypes...>::m_types;
} } // namespace cppa::detail
#endif // TUPLE_VALS_HPP
......@@ -39,7 +39,6 @@
#include "cppa/anything.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/tuple_view.hpp"
#include "cppa/util/a_matches_b.hpp"
namespace cppa {
......
......@@ -39,11 +39,11 @@
#include "cppa/tuple_view.hpp"
#include "cppa/util/at.hpp"
#include "cppa/util/pop_back.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/element_at.hpp"
#include "cppa/util/callable_trait.hpp"
#include "cppa/util/reverse_type_list.hpp"
//#include "cppa/util/reverse_type_list.hpp"
namespace cppa { namespace detail {
......@@ -51,13 +51,13 @@ template<size_t N, typename F, typename ResultType, class Tuple,
typename ArgTypeList, typename... Args>
struct invoke_helper
{
typedef typename util::reverse_type_list<ArgTypeList>::type rlist;
typedef typename rlist::head_type back_type;
//typedef typename util::reverse_type_list<ArgTypeList>::type rlist;
typedef typename ArgTypeList::back back;
typedef typename util::element_at<N, Tuple>::type tuple_val_type;
typedef typename util::pop_back<ArgTypeList>::type next_list;
typedef typename util::tl_pop_back<ArgTypeList>::type next_list;
inline static ResultType _(F& f, Tuple const& t, Args const&... args)
{
static_assert(std::is_convertible<tuple_val_type, back_type>::value,
static_assert(std::is_convertible<tuple_val_type, back>::value,
"tuple element is not convertible to expected argument");
return invoke_helper<N - 1, F, ResultType, Tuple, next_list, tuple_val_type, Args...>
::_(f, t, get<N>(t), args...);
......
......@@ -41,14 +41,12 @@
#include "cppa/any_tuple.hpp"
#include "cppa/invoke_rules.hpp"
#include "cppa/util/pop_back.hpp"
#include "cppa/util/duration.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/enable_if.hpp"
#include "cppa/util/arg_match_t.hpp"
#include "cppa/util/eval_first_n.hpp"
#include "cppa/util/callable_trait.hpp"
#include "cppa/util/type_list_apply.hpp"
#include "cppa/util/filter_type_list.hpp"
#include "cppa/util/concat_type_lists.hpp"
......@@ -88,19 +86,19 @@ class invoke_rule_builder
typedef util::type_list<TypeList...> raw_types;
static const bool is_complete =
!std::is_same<arg_match_t, typename raw_types::back_type>::value;
static constexpr bool is_complete =
!std::is_same<arg_match_t, typename raw_types::back>::value;
typedef typename util::if_else_c<is_complete == false,
typename util::pop_back<raw_types>::type,
typename util::tl_pop_back<raw_types>::type,
util::wrapped<raw_types> >::type
types;
static_assert(util::tl_find<types, arg_match_t>::value == -1,
"arg_match is allowed only as last parameter for on()");
typedef typename util::type_list_apply<types,
detail::implicit_conversions>::type
typedef typename util::tl_apply<types,
detail::implicit_conversions>::type
converted_types;
typedef typename pattern_type_from_type_list<converted_types>::type
......@@ -124,7 +122,7 @@ class invoke_rule_builder
typedef typename get_callable_trait<F>::type ctrait;
typedef typename ctrait::arg_types raw_types;
static_assert(raw_types::size > 0, "functor has no arguments");
typedef typename type_list_apply<raw_types,rm_ref>::type new_types;
typedef typename tl_apply<raw_types,rm_ref>::type new_types;
typedef typename concat_type_lists<converted_types,new_types>::type types;
typedef typename pattern_type_from_type_list<types>::type epattern;
typedef typename epattern::tuple_view_type tuple_view_type;
......@@ -167,7 +165,7 @@ class on_the_fly_invoke_rule_builder
typedef typename get_callable_trait<F>::type ctrait;
typedef typename ctrait::arg_types raw_types;
static_assert(raw_types::size > 0, "functor has no arguments");
typedef typename type_list_apply<raw_types,rm_ref>::type types;
typedef typename tl_apply<raw_types,rm_ref>::type types;
typedef typename pattern_type_from_type_list<types>::type pattern_type;
typedef typename pattern_type::tuple_view_type tuple_view_type;
typedef invokable_impl<tuple_view_type, pattern_type, F> impl;
......
......@@ -40,7 +40,7 @@
#include "cppa/uniform_type_info.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/type_list_apply.hpp"
#include "cppa/util/filter_type_list.hpp"
#include "cppa/detail/tdata.hpp"
#include "cppa/detail/types_array.hpp"
......
......@@ -45,8 +45,6 @@
#include "cppa/util/replace_type.hpp"
#include "cppa/util/is_comparable.hpp"
#include "cppa/util/compare_tuples.hpp"
#include "cppa/util/eval_type_list.hpp"
#include "cppa/util/type_list_apply.hpp"
#include "cppa/util/is_legal_tuple_type.hpp"
#include "cppa/detail/tuple_vals.hpp"
......@@ -77,12 +75,14 @@ class tuple
static_assert(sizeof...(ElementTypes) > 0, "tuple is empty");
static_assert(util::eval_type_list<element_types,
util::is_legal_tuple_type>::value,
static_assert(util::tl_forall<element_types, util::is_legal_tuple_type>::value,
"illegal types in tuple definition: "
"pointers and references are prohibited");
typedef detail::tuple_vals<ElementTypes...> vals_t;
typedef detail::tuple_vals<ElementTypes...> tuple_vals_type;
//typedef detail::tuple_vals<ElementTypes...> vals_t;
typedef detail::abstract_tuple vals_t;
cow_ptr<vals_t> m_vals;
......@@ -91,7 +91,7 @@ class tuple
/**
* @brief Initializes each element with its default constructor.
*/
tuple() : m_vals(new vals_t)
tuple() : m_vals(new tuple_vals_type)
{
}
......@@ -99,7 +99,7 @@ class tuple
* @brief Initializes the tuple with @p args.
* @param args Initialization values.
*/
tuple(ElementTypes const&... args) : m_vals(new vals_t(args...))
tuple(ElementTypes const&... args) : m_vals(new tuple_vals_type(args...))
{
}
......@@ -121,6 +121,11 @@ class tuple
return m_vals->at(p);
}
inline void* mutable_at(size_t p)
{
return m_vals->mutable_at(p);
}
/**
* @brief Gets {@link uniform_type_info uniform type information}
* of an element.
......@@ -195,19 +200,23 @@ tuple<Types...> make_tuple(Types const&... args);
template<size_t N, typename... Types>
const typename util::at<N, Types...>::type& get(tuple<Types...> const& tup)
{
return get<N>(tup.vals()->data());
typedef typename util::at<N, Types...>::type result_type;
return *reinterpret_cast<result_type const*>(tup.at(N));
//return get<N>(tup.vals()->data());
}
template<size_t N, typename... Types>
typename util::at<N, Types...>::type& get_ref(tuple<Types...>& tup)
{
return get_ref<N>(tup.m_vals->data_ref());
typedef typename util::at<N, Types...>::type result_type;
return *reinterpret_cast<result_type*>(tup.mutable_at(N));
//return get_ref<N>(tup.m_vals->data_ref());
}
template<typename... Types>
typename tuple_type_from_type_list<
typename util::type_list_apply<util::type_list<Types...>,
detail::implicit_conversions>::type>::type
typename util::tl_apply<util::type_list<Types...>,
detail::implicit_conversions>::type>::type
make_tuple(Types const&... args)
{
return { args... };
......
......@@ -38,7 +38,6 @@
#include "cppa/util/at.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/a_matches_b.hpp"
#include "cppa/util/fixed_vector.hpp"
#include "cppa/util/compare_tuples.hpp"
......
......@@ -31,7 +31,6 @@
#ifndef UTIL_HPP
#define UTIL_HPP
#include "cppa/util/a_matches_b.hpp"
#include "cppa/util/apply.hpp"
#include "cppa/util/callable_trait.hpp"
#include "cppa/util/compare_tuples.hpp"
......@@ -40,8 +39,6 @@
#include "cppa/util/disjunction.hpp"
#include "cppa/util/enable_if.hpp"
#include "cppa/util/eval_first_n.hpp"
#include "cppa/util/eval_type_list.hpp"
#include "cppa/util/eval_type_lists.hpp"
#include "cppa/util/filter_type_list.hpp"
#include "cppa/util/first_n.hpp"
#include "cppa/util/has_copy_member_fun.hpp"
......@@ -51,11 +48,9 @@
#include "cppa/util/is_one_of.hpp"
#include "cppa/util/remove_const_reference.hpp"
#include "cppa/util/replace_type.hpp"
#include "cppa/util/reverse_type_list.hpp"
#include "cppa/util/single_reader_queue.hpp"
#include "cppa/util/singly_linked_list.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/type_list_apply.hpp"
#include "cppa/util/void_type.hpp"
#endif // UTIL_HPP
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011, 2012 *
* Dominik Charousset <dominik.charousset@haw-hamburg.de> *
* *
* This file is part of libcppa. *
* libcppa is free software: you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License *
* or (at your option) any later version. *
* *
* libcppa is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
\******************************************************************************/
#ifndef CPPA_UTIL_A_MATCHES_B_HPP
#define CPPA_UTIL_A_MATCHES_B_HPP
/*
#include <type_traits>
#include "cppa/any_type.hpp"
#include "cppa/util/void_type.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/is_one_of.hpp"
#include "cppa/util/conjunction.hpp"
namespace cppa { namespace detail {
template<typename HeadA, typename TailA, typename HeadB, typename TailB>
struct amb_helper : util::conjunction<util::is_one_of<HeadA, HeadB, any_type>,
amb_helper<typename TailA::head_type,
typename TailA::tail_type,
typename TailB::head_type,
typename TailB::tail_type>>
{
static_assert( std::is_same<HeadB, any_type>::value == false
&& std::is_same<HeadB, any_type*>::value == false,
"any_type in right hand type list");
};
template<>
struct amb_helper<util::void_type, util::type_list<>,
util::void_type, util::type_list<>> : std::true_type
{
};
template<typename TailA>
struct amb_helper<any_type*, TailA, util::void_type, util::type_list<>>
: amb_helper<typename TailA::head_type,
typename TailA::tail_type,
util::void_type,
util::type_list<>>
{
};
template<typename TailA, typename HeadB, typename TailB>
struct amb_helper<any_type*, TailA, HeadB, TailB>
: util::disjunction<amb_helper<typename TailA::head_type,
typename TailA::tail_type,
HeadB,
TailB>,
amb_helper<any_type*,
TailA,
typename TailB::head_type,
typename TailB::tail_type>>
{
static_assert(std::is_same<HeadB, any_type>::value == false,
"any_type in right hand type list");
};
} } // namespace cppa::detail
namespace cppa { namespace util {
template<typename ListA, typename ListB>
struct a_matches_b : detail::amb_helper<typename ListA::head_type,
typename ListA::tail_type,
typename ListB::head_type,
typename ListB::tail_type>
{
};
} } // namespace cppa::util
*/
#endif // CPPA_UTIL_A_MATCHES_B_HPP
......@@ -36,7 +36,6 @@
#include "cppa/util/type_list.hpp"
#include "cppa/util/eval_first_n.hpp"
#include "cppa/util/is_comparable.hpp"
#include "cppa/util/eval_type_lists.hpp"
namespace cppa { namespace detail {
......@@ -77,10 +76,11 @@ bool compare_tuples(LhsTuple<LhsTypes...> const& lhs,
{
static_assert(sizeof...(LhsTypes) == sizeof...(RhsTypes),
"could not compare tuples of different size");
static_assert(util::eval_type_lists<util::type_list<LhsTypes...>,
util::type_list<RhsTypes...>,
util::is_comparable>::value,
static_assert(tl_zipped_forall<type_list<type_pair<LhsTypes,RhsTypes>...>,
is_comparable>::value,
"types of lhs are not comparable to the types of rhs");
return detail::cmp_helper<(sizeof...(LhsTypes) - 1),
LhsTuple<LhsTypes...>,
RhsTuple<RhsTypes...>>::cmp(lhs, rhs);
......@@ -91,19 +91,17 @@ template<template<typename...> class LhsTuple, typename... LhsTypes,
bool compare_first_elements(LhsTuple<LhsTypes...> const& lhs,
RhsTuple<RhsTypes...> const& rhs)
{
typedef util::type_list<LhsTypes...> lhs_types;
typedef util::type_list<RhsTypes...> rhs_types;
static constexpr size_t lhs_size = sizeof...(LhsTypes);
static constexpr size_t rhs_size = sizeof...(RhsTypes);
static constexpr size_t cmp_size = (lhs_size < rhs_size)
? lhs_size
: rhs_size;
static_assert(util::eval_first_n<cmp_size,
lhs_types,
rhs_types,
util::is_comparable>::value,
static constexpr size_t cmp_size = (sizeof...(LhsTypes) < sizeof...(RhsTypes))
? sizeof...(LhsTypes)
: sizeof...(RhsTypes);
typedef util::type_list<LhsTypes...> lhs_tlist;
typedef util::type_list<RhsTypes...> rhs_tlist;
typedef typename tl_first_n<cmp_size, lhs_tlist>::type lhs_sublist;
typedef typename tl_first_n<cmp_size, rhs_tlist>::type rhs_sublist;
typedef typename tl_zip<lhs_sublist, rhs_sublist>::type zipped_sublists;
static_assert(tl_zipped_forall<zipped_sublists, is_comparable>::value,
"types of lhs are not comparable to the types of rhs");
return detail::cmp_helper<(cmp_size - 1),
......
......@@ -54,7 +54,7 @@ struct eval_first_n<N, type_list<TypesA...>, type_list<TypesB...>, What>
typedef typename first_n<N, first_list>::type slist_a;
typedef typename first_n<N, second_list>::type slist_b;
static const bool value = eval_type_lists<slist_a, slist_b, What>::value;
static constexpr bool value = eval_type_lists<slist_a, slist_b, What>::value;
};
} } // namespace cppa::util
......
......@@ -42,18 +42,18 @@ namespace cppa { namespace util {
template <class List, template <typename> class What>
struct eval_type_list
{
typedef typename List::head_type head_type;
typedef typename List::tail_type tail_type;
typedef typename List::head head;
typedef typename List::tail tail;
static const bool value =
What<head_type>::value
&& eval_type_list<tail_type, What>::value;
static constexpr bool value =
What<head>::value
&& eval_type_list<tail, What>::value;
};
template <template <typename> class What>
struct eval_type_list<type_list<>, What>
{
static const bool value = true;
static constexpr bool value = true;
};
} } // namespace cppa::util
......
......@@ -45,24 +45,24 @@ template <class ListA, class ListB,
struct eval_type_lists
{
typedef typename ListA::head_type head_type_a;
typedef typename ListA::tail_type tail_type_a;
typedef typename ListA::head head_a;
typedef typename ListA::tail tail_a;
typedef typename ListB::head_type head_type_b;
typedef typename ListB::tail_type tail_type_b;
typedef typename ListB::head head_b;
typedef typename ListB::tail tail_b;
static const bool value =
!std::is_same<head_type_a, void_type>::value
&& !std::is_same<head_type_b, void_type>::value
&& What<head_type_a, head_type_b>::value
&& eval_type_lists<tail_type_a, tail_type_b, What>::value;
static constexpr bool value =
!std::is_same<head_a, void_type>::value
&& !std::is_same<head_b, void_type>::value
&& What<head_a, head_b>::value
&& eval_type_lists<tail_a, tail_b, What>::value;
};
template <template <typename, typename> class What>
struct eval_type_lists<type_list<>, type_list<>, What>
{
static const bool value = true;
static constexpr bool value = true;
};
} } // namespace cppa::util
......
......@@ -47,11 +47,11 @@ template<size_t N, typename List>
struct n_
{
typedef typename util::element_at<N - 1, List>::type head_type;
typedef typename util::element_at<N - 1, List>::type head;
typedef typename util::if_else<std::is_same<util::void_type, head_type>,
typedef typename util::if_else<std::is_same<util::void_type, head>,
util::type_list<>,
util::wrapped<util::type_list<head_type>>>::type
util::wrapped<util::type_list<head>>>::type
head_list;
typedef typename n_<N - 1, List>::type tail_list;
......
......@@ -52,7 +52,7 @@ class has_copy_member_fun
public:
static const bool value = std::is_same<bool, result_type>::value;
static constexpr bool value = std::is_same<bool, result_type>::value;
};
......
......@@ -44,7 +44,7 @@ struct is_array_of
{
typedef typename std::remove_all_extents<T>::type step1_type;
typedef typename std::remove_cv<step1_type>::type step2_type;
static const bool value = std::is_array<T>::value
static constexpr bool value = std::is_array<T>::value
&& std::is_same<step2_type, U>::value;
};
......
......@@ -64,7 +64,7 @@ class is_comparable
public:
static const bool value = std::is_same<bool, result_type>::value;
static constexpr bool value = std::is_same<bool, result_type>::value;
};
......
......@@ -54,7 +54,7 @@ class is_copyable_
public:
static const bool value = std::is_same<bool, result_type>::value;
static constexpr bool value = std::is_same<bool, result_type>::value;
};
......@@ -64,7 +64,7 @@ class is_copyable_<true, T>
public:
static const bool value = false;
static constexpr bool value = false;
};
......
......@@ -64,7 +64,7 @@ class is_forward_iterator
public:
static const bool value = std::is_same<bool, result_type>::value;
static constexpr bool value = std::is_same<bool, result_type>::value;
};
......
......@@ -61,7 +61,7 @@ class is_iterable
public:
static const bool value = util::is_primitive<T>::value == false
static constexpr bool value = util::is_primitive<T>::value == false
&& std::is_same<bool, result_type>::value;
};
......
......@@ -38,7 +38,7 @@ namespace cppa { namespace util {
template<typename T>
struct is_legal_tuple_type
{
static const bool value = std::is_pointer<T>::value == false
static constexpr bool value = std::is_pointer<T>::value == false
&& std::is_reference<T>::value == false
&& std::is_array<T>::value == false;
};
......
......@@ -50,7 +50,7 @@ namespace cppa { namespace util {
template<typename T>
struct is_primitive
{
static const bool value = detail::type_to_ptype<T>::ptype != pt_null;
static constexpr bool value = detail::type_to_ptype<T>::ptype != pt_null;
};
} } // namespace cppa::util
......
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011, 2012 *
* Dominik Charousset <dominik.charousset@haw-hamburg.de> *
* *
* This file is part of libcppa. *
* libcppa is free software: you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License *
* or (at your option) any later version. *
* *
* libcppa is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
\******************************************************************************/
#ifndef CPPA_UTIL_REVERSE_TYPE_LIST_HPP
#define CPPA_UTIL_REVERSE_TYPE_LIST_HPP
#include "cppa/util/type_list.hpp"
#include "cppa/util/concat_type_lists.hpp"
namespace cppa { namespace util {
template<typename ListFrom, typename ListTo = type_list<>>
struct reverse_type_list;
template<typename HeadA, typename... TailA, typename... ListB>
struct reverse_type_list<type_list<HeadA, TailA...>, type_list<ListB...>>
{
typedef typename reverse_type_list<type_list<TailA...>,
type_list<HeadA, ListB...>>::type
type;
};
template<typename... Types>
struct reverse_type_list<type_list<>, type_list<Types...>>
{
typedef type_list<Types...> type;
};
} } // namespace cppa::util
#endif // CPPA_UTIL_REVERSE_TYPE_LIST_HPP
......@@ -34,6 +34,7 @@
#include <typeinfo>
#include "cppa/util/if_else.hpp"
#include "cppa/util/type_pair.hpp"
#include "cppa/util/void_type.hpp"
namespace cppa {
......@@ -51,9 +52,9 @@ template<typename... Types> struct type_list;
template<>
struct type_list<>
{
typedef void_type head_type;
typedef void_type back_type;
typedef type_list<> tail_type;
typedef void_type head;
typedef void_type back;
typedef type_list<> tail;
static const size_t size = 0;
};
......@@ -61,48 +62,66 @@ template<typename Head, typename... Tail>
struct type_list<Head, Tail...>
{
typedef uniform_type_info const* uti_ptr;
typedef Head head;
typedef Head head_type;
typedef type_list<Tail...> tail_type;
typedef type_list<Tail...> tail;
typedef typename if_else_c<sizeof...(Tail) == 0,
Head,
wrapped<typename tail_type::back_type> >::type
back_type;
wrapped<typename tail::back> >::type
back;
static const size_t size = sizeof...(Tail) + 1;
type_list()
{
init<type_list>(m_arr);
}
};
inline uniform_type_info const& at(size_t pos) const
{
return *m_arr[pos];
}
/**
* @brief Zips two lists of equal size.
*
* Creates a list formed from the two lists @p ListA and @p ListB,
* e.g., tl_zip<type_list<int,double>,type_list<float,string>>::type
* is type_list<type_pair<int,float>,type_pair<double,string>>.
*/
template<class ListA, class ListB>
struct tl_zip;
template<typename TypeList>
static void init(uti_ptr* what)
{
what[0] = uniform_typeid(typeid(typename TypeList::head_type));
if (TypeList::size > 1)
{
++what;
init<typename TypeList::tail_type>(what);
}
}
template<typename... LhsElements, typename... RhsElements>
struct tl_zip<type_list<LhsElements...>, type_list<RhsElements...> >
{
static_assert(type_list<LhsElements...>::size ==
type_list<RhsElements...>::size,
"Lists have different size");
typedef type_list<type_pair<LhsElements, RhsElements>...> type;
};
private:
template<class From, typename... Elements>
struct tl_reverse_impl;
uti_ptr m_arr[size];
template<typename T0, typename... T, typename... E>
struct tl_reverse_impl<type_list<T0, T...>, E...>
{
typedef typename tl_reverse_impl<type_list<T...>, T0, E...>::type type;
};
template<typename... E>
struct tl_reverse_impl<type_list<>, E...>
{
typedef type_list<E...> type;
};
// type_list::find
/**
* @brief Creates a new list wih elements in reversed order.
*/
template<class List>
struct tl_reverse
{
typedef typename tl_reverse_impl<List>::type type;
};
/**
* @brief Finds the first element of type @p What beginning at
* index @p Pos.
*/
template<class List, typename What, int Pos = 0>
struct tl_find;
......@@ -120,7 +139,31 @@ struct tl_find<type_list<Head, Tail...>, What, Pos>
: tl_find<type_list<Tail...>, What, Pos+1>::value;
};
// type_list::forall
template<size_t N, class List, typename... T>
struct tl_first_n_impl;
template<class List, typename... T>
struct tl_first_n_impl<0, List, T...>
{
typedef type_list<T...> type;
};
template<size_t N, typename L0, typename... L, typename... T>
struct tl_first_n_impl<N, type_list<L0, L...>, T...>
{
typedef typename tl_first_n_impl<N-1, type_list<L...>, T..., L0>::type type;
};
/**
* @brief Creates a new list from the first @p N elements of @p List.
*/
template<size_t N, class List>
struct tl_first_n
{
static_assert(N > 0, "N == 0");
static_assert(List::size >= N, "List::size < N");
typedef typename tl_first_n_impl<N, List>::type type;
};
/**
* @brief Tests whether a predicate holds for all elements of a list.
......@@ -128,20 +171,83 @@ struct tl_find<type_list<Head, Tail...>, What, Pos>
template<class List, template <typename> class Predicate>
struct tl_forall
{
typedef typename List::head_type head_type;
typedef typename List::tail_type tail_type;
static const bool value =
Predicate<head_type>::value
&& tl_forall<tail_type, Predicate>::value;
static constexpr bool value =
Predicate<typename List::head>::value
&& tl_forall<typename List::tail, Predicate>::value;
};
template<template <typename> class Predicate>
struct tl_forall<type_list<>, Predicate>
{
static const bool value = true;
static constexpr bool value = true;
};
/**
* @brief Tests whether a predicate holds for all elements of a zipped list.
*/
template<class ZippedList, template <typename, typename> class Predicate>
struct tl_zipped_forall
{
typedef typename ZippedList::head head;
static constexpr bool value =
Predicate<typename head::first, typename head::second>::value
&& tl_zipped_forall<typename ZippedList::tail, Predicate>::value;
};
template<template <typename, typename> class Predicate>
struct tl_zipped_forall<type_list<>, Predicate>
{
static constexpr bool value = true;
};
/**
* @brief Concatenates two lists.
*/
template<typename ListA, typename ListB>
struct tl_concat;
template<typename... ListATypes, typename... ListBTypes>
struct tl_concat<type_list<ListATypes...>, type_list<ListBTypes...> >
{
typedef type_list<ListATypes..., ListBTypes...> type;
};
/**
* @brief Applies a "template function" to each element in the list.
*/
template<typename List, template <typename> class What>
struct tl_apply;
template<template <typename> class What, typename... Elements>
struct tl_apply<type_list<Elements...>, What>
{
typedef type_list<typename What<Elements>::type...> type;
};
/**
* @brief Applies a binary "template function" to each element
* in the zipped list.
*/
template<typename List, template<typename, typename> class What>
struct tl_zipped_apply;
template<template<typename, typename> class What, typename... T>
struct tl_zipped_apply<type_list<T...>, What>
{
typedef type_list<typename What<typename T::first, typename T::second>::type...> type;
};
/**
* @brief Creates a new list wih all but the last element of @p List.
*/
template<class List>
struct tl_pop_back
{
typedef typename tl_reverse<List>::type rlist;
typedef typename tl_reverse<typename rlist::tail>::type type;
};
} } // namespace cppa::util
#endif // LIBCPPA_UTIL_TYPE_LIST_HPP
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011, 2012 *
* Dominik Charousset <dominik.charousset@haw-hamburg.de> *
* *
* This file is part of libcppa. *
* libcppa is free software: you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License *
* or (at your option) any later version. *
* *
* libcppa is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
\******************************************************************************/
#ifndef TYPE_LIST_APPLY_HPP
#define TYPE_LIST_APPLY_HPP
#include "cppa/util/type_list.hpp"
#include "cppa/util/concat_type_lists.hpp"
namespace cppa { namespace util {
/**
* @brief Apply @p What to each element of @p List.
*/
template <typename List, template <typename> class What>
struct type_list_apply
{
typedef typename What<typename List::head_type>::type head_type;
typedef typename concat_type_lists<
type_list<head_type>,
typename type_list_apply<typename List::tail_type, What>::type>::type
type;
};
template<template <typename> class What>
struct type_list_apply<type_list<>, What>
{
typedef type_list<> type;
};
} } // namespace cppa::util
#endif // TYPE_LIST_APPLY_HPP
......@@ -28,24 +28,18 @@
\******************************************************************************/
#ifndef POP_BACK_HPP
#define POP_BACK_HPP
#include "cppa/util/type_list.hpp"
#include "cppa/util/reverse_type_list.hpp"
#ifndef TYPE_PAIR_HPP
#define TYPE_PAIR_HPP
namespace cppa { namespace util {
template<class C>
struct pop_back;
template<typename... Tn>
struct pop_back< type_list<Tn...> >
template<typename First, typename Second>
struct type_pair
{
typedef typename reverse_type_list<type_list<Tn...>>::type rlist;
typedef typename reverse_type_list<typename rlist::tail_type>::type type;
typedef First first;
typedef Second second;
};
} } // namespace cppa::util
#endif // POP_BACK_HPP
#endif // TYPE_PAIR_HPP
......@@ -38,8 +38,8 @@ template<typename... Types> struct type_list;
struct void_type
{
typedef void_type head_type;
typedef type_list<> tail_type;
typedef void_type head;
typedef type_list<> tail;
};
inline bool operator==(void_type const&, void_type const&) { return true; }
......
......@@ -34,8 +34,27 @@ typedef std::pair<int,int> foobar;
static detail::types_array<int,anything,float> arr1;
static detail::types_array<int,anything,foobar> arr2;
template<template <typename, typename> class Tpl, typename Arg1>
struct tbind
{
template<typename Arg2>
struct type
{
static constexpr bool value = Tpl<Arg1, Arg2>::value;
};
};
template<template<typename> class Predicate, class Value>
struct foobaz
{
static constexpr bool value = Predicate<Value>::value;
};
size_t test__pattern()
{
cout << "foobaz: " << foobaz<tbind<std::is_same, void>::type, void>::value << endl;
announce<foobar>(&foobar::first, &foobar::second);
plot(arr1);
......
......@@ -26,7 +26,7 @@ size_t test__type_list()
CPPA_CHECK((is_same<int, int_typedef>::value));
typedef type_list<int, float, std::string> l1;
typedef reverse_type_list<l1>::type r1;
typedef typename tl_reverse<l1>::type r1;
CPPA_CHECK((is_same<int, element_at<0, l1>::type>::value));
CPPA_CHECK((is_same<float, element_at<1, l1>::type>::value));
......@@ -40,8 +40,8 @@ size_t test__type_list()
typedef concat_type_lists<type_list<int>, l1>::type l2;
CPPA_CHECK((is_same<int, l2::head_type>::value));
CPPA_CHECK((is_same<l1, l2::tail_type>::value));
CPPA_CHECK((is_same<int, l2::head>::value));
CPPA_CHECK((is_same<l1, l2::tail>::value));
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