Permalink
Browse files

maintenance

this patch removes the old `apply_tuple` function family
(replaced by `apply_args`), removes `partially_apply_args`
(use `int_list` for indices instead), and cleans up unit test macros
  • Loading branch information...
1 parent 98998f9 commit 996ab01de53ed49969ac61c4aef573a4461e4d8f @Neverlord Neverlord committed Feb 7, 2013
Showing with 348 additions and 551 deletions.
  1. +16 −17 cppa.files
  2. +0 −1 cppa/detail/decorated_tuple.hpp
  3. +8 −3 cppa/detail/get_behavior.hpp
  4. +51 −78 cppa/detail/projection.hpp
  5. +3 −3 cppa/guard_expr.hpp
  6. +4 −2 cppa/tpartial_function.hpp
  7. +0 −23 cppa/util/apply_args.hpp
  8. +0 −138 cppa/util/apply_tuple.hpp
  9. +22 −2 cppa/util/int_list.hpp
  10. +5 −5 unit_testing/CMakeLists.txt
  11. +69 −69 unit_testing/test.hpp
  12. +0 −42 unit_testing/test__type_list.cpp
  13. +1 −1 unit_testing/{test__atom.cpp → test_atom.cpp}
  14. +25 −25 unit_testing/{test__fixed_vector.cpp → test_fixed_vector.cpp}
  15. +1 −1 unit_testing/{test__intrusive_containers.cpp → test_intrusive_containers.cpp}
  16. +16 −16 unit_testing/{test__intrusive_ptr.cpp → test_intrusive_ptr.cpp}
  17. +3 −3 unit_testing/{test__local_group.cpp → test_local_group.cpp}
  18. +15 −63 unit_testing/{test__match.cpp → test_match.cpp}
  19. +59 −0 unit_testing/test_metaprogramming.cpp
  20. +8 −12 unit_testing/{test__primitive_variant.cpp → test_primitive_variant.cpp}
  21. +4 −2 unit_testing/{test__remote_actor.cpp → test_remote_actor.cpp}
  22. +1 −1 unit_testing/{test__ripemd_160.cpp → test_ripemd_160.cpp}
  23. +1 −1 unit_testing/{test__serialization.cpp → test_serialization.cpp}
  24. +32 −39 unit_testing/{test__spawn.cpp → test_spawn.cpp}
  25. +1 −1 unit_testing/{test__sync_send.cpp → test_sync_send.cpp}
  26. +1 −1 unit_testing/{test__tuple.cpp → test_tuple.cpp}
  27. +1 −1 unit_testing/{test__uniform_type.cpp → test_uniform_type.cpp}
  28. +1 −1 unit_testing/{test__yield_interface.cpp → test_yield_interface.cpp}
View
@@ -136,7 +136,6 @@ cppa/tuple_cast.hpp
cppa/uniform_type_info.hpp
cppa/util/abstract_uniform_type_info.hpp
cppa/util/apply_args.hpp
-cppa/util/apply_tuple.hpp
cppa/util/arg_match_t.hpp
cppa/util/at.hpp
cppa/util/buffer.hpp
@@ -274,21 +273,21 @@ src/yield_interface.cpp
unit_testing/ping_pong.cpp
unit_testing/ping_pong.hpp
unit_testing/test.hpp
-unit_testing/test__atom.cpp
-unit_testing/test__fixed_vector.cpp
-unit_testing/test__intrusive_containers.cpp
-unit_testing/test__intrusive_ptr.cpp
-unit_testing/test__local_group.cpp
-unit_testing/test__match.cpp
-unit_testing/test__primitive_variant.cpp
-unit_testing/test__remote_actor.cpp
-unit_testing/test__ripemd_160.cpp
-unit_testing/test__serialization.cpp
-unit_testing/test__spawn.cpp
-unit_testing/test__sync_send.cpp
-unit_testing/test__tuple.cpp
-unit_testing/test__type_list.cpp
-unit_testing/test__uniform_type.cpp
-unit_testing/test__yield_interface.cpp
+unit_testing/test_atom.cpp
+unit_testing/test_fixed_vector.cpp
+unit_testing/test_intrusive_containers.cpp
+unit_testing/test_intrusive_ptr.cpp
+unit_testing/test_local_group.cpp
+unit_testing/test_match.cpp
+unit_testing/test_primitive_variant.cpp
+unit_testing/test_remote_actor.cpp
+unit_testing/test_ripemd_160.cpp
+unit_testing/test_serialization.cpp
+unit_testing/test_spawn.cpp
+unit_testing/test_sync_send.cpp
+unit_testing/test_tuple.cpp
+unit_testing/test_metaprogramming.cpp
+unit_testing/test_uniform_type.cpp
+unit_testing/test_yield_interface.cpp
cppa/memory_cached_mixin.hpp
unit_testing/test.cpp
@@ -40,7 +40,6 @@
#include "cppa/uniform_type_info.hpp"
#include "cppa/util/type_list.hpp"
-#include "cppa/util/apply_tuple.hpp"
#include "cppa/util/fixed_vector.hpp"
#include "cppa/detail/tuple_vals.hpp"
@@ -34,7 +34,8 @@
#include <type_traits>
#include "cppa/util/rm_ref.hpp"
-#include "cppa/util/apply_tuple.hpp"
+#include "cppa/util/int_list.hpp"
+#include "cppa/util/apply_args.hpp"
#include "cppa/detail/tdata.hpp"
#include "cppa/scheduled_actor.hpp"
@@ -73,7 +74,9 @@ class ftor_behavior<true, true, F, Args...> : public scheduled_actor {
ftor_behavior(F ptr, const Args&... args) : m_fun(ptr), m_args(args...) { }
- virtual void act() { util::apply_tuple(m_fun, m_args); }
+ virtual void act() {
+ util::apply_args(m_fun, m_args, util::get_indices(m_args));
+ }
};
@@ -115,7 +118,9 @@ class ftor_behavior<false, true, F, Args...> : public scheduled_actor {
, m_args(args...) {
}
- virtual void act() { util::apply_tuple(m_fun, m_args); }
+ virtual void act() {
+ util::apply_args(m_fun, m_args, util::get_indices(m_args));
+ }
};
View
@@ -38,42 +38,34 @@
#include "cppa/util/rm_option.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/util/apply_args.hpp"
-#include "cppa/util/apply_tuple.hpp"
#include "cppa/util/left_or_right.hpp"
#include "cppa/detail/tdata.hpp"
namespace cppa { namespace detail {
-template<class PartialFun>
-struct projection_helper {
- const PartialFun& fun;
- projection_helper(const PartialFun& pfun) : fun(pfun) { }
- template<typename... Args>
- bool operator()(Args&&... args) const {
- if (fun.defined_at(std::forward<Args>(args)...)) {
- fun(std::forward<Args>(args)...);
- return true;
- }
- return false;
- }
-};
-
-template<class PartialFun>
-struct result_fetching_projection_helper {
- typedef typename PartialFun::result_type result_type;
- const PartialFun& fun;
- result_type& result;
- result_fetching_projection_helper(const PartialFun& pfun, result_type& res)
- : fun(pfun), result(res) { }
- template<typename... Args>
- bool operator()(Args&&... args) const {
- if (fun.defined_at(std::forward<Args>(args)...)) {
- result = fun(std::forward<Args>(args)...);
- return true;
- }
- return false;
- }
+template<typename Fun, typename Tuple, long... Is>
+inline bool is_defined_at(Fun& f, Tuple& tup, util::int_list<Is...>) {
+ return f.defined_at(get_cv_aware<Is>(tup)...);
+}
+
+template<typename ProjectionFuns, typename... Args>
+struct collected_args_tuple {
+ typedef typename tdata_from_type_list<
+ typename util::tl_zip<
+ typename util::tl_map<
+ ProjectionFuns,
+ util::get_result_type,
+ util::rm_option
+ >::type,
+ typename util::tl_map<
+ util::type_list<Args...>,
+ mutable_gref_wrapped
+ >::type,
+ util::left_or_right
+ >::type
+ >::type
+ type;
};
/**
@@ -95,84 +87,65 @@ class projection {
projection(const projection&) = default;
/**
- * @brief Invokes @p fun with a projection of <tt>args...</tt>.
+ * @brief Invokes @p fun with a projection of <tt>args...</tt> and stores
+ * the result of @p fun in @p result.
*/
template<class PartialFun>
- bool operator()(PartialFun& fun, Args... args) const {
- typedef typename util::tl_zip<
- typename util::tl_map<
- ProjectionFuns,
- util::get_result_type,
- util::rm_option
- >::type,
- typename util::tl_map<
- util::type_list<Args...>,
- mutable_gref_wrapped
- >::type,
- util::left_or_right
- >::type
- collected_args;
-
- typename tdata_from_type_list<collected_args>::type pargs;
+ bool invoke(PartialFun& fun, typename PartialFun::result_type& result, Args... args) const {
+ typename collected_args_tuple<ProjectionFuns,Args...>::type pargs;
if (collect(pargs, m_funs, std::forward<Args>(args)...)) {
- projection_helper<PartialFun> helper{fun};
auto indices = util::get_indices(pargs);
- return util::apply_args(helper, pargs, indices);
+ if (is_defined_at(fun, pargs, indices)) {
+ result = util::apply_args(fun, pargs, indices);
+ return true;
+ }
}
return false;
}
+ /**
+ * @brief Invokes @p fun with a projection of <tt>args...</tt>.
+ */
template<class PartialFun>
- bool invoke(PartialFun& fun, typename PartialFun::result_type& result, Args... args) const {
- typedef typename PartialFun::result_type result_type;
- typedef typename util::tl_zip<
- typename util::tl_map<
- ProjectionFuns,
- util::get_result_type,
- util::rm_option
- >::type,
- typename util::tl_map<
- util::type_list<Args...>,
- mutable_gref_wrapped
- >::type,
- util::left_or_right
- >::type
- collected_args;
-
- typename tdata_from_type_list<collected_args>::type pargs;
+ bool operator()(PartialFun& fun, Args... args) const {
+ typename collected_args_tuple<ProjectionFuns,Args...>::type pargs;
+ auto indices = util::get_indices(pargs);
if (collect(pargs, m_funs, std::forward<Args>(args)...)) {
- result_fetching_projection_helper<PartialFun> helper{fun, result};
- auto indices = util::get_indices(pargs);
- return util::apply_args(helper, pargs, indices);
+ if (is_defined_at(fun, pargs, indices)) {
+ util::apply_args(fun, pargs, indices);
+ return true;
+ }
}
return false;
}
private:
template<typename Storage, typename T>
- static inline bool fetch_(Storage& storage, T&& value) {
+ static inline bool store(Storage& storage, T&& value) {
storage = std::forward<T>(value);
return true;
}
template<class Storage>
- static inline bool fetch_(Storage& storage, option<Storage>&& value) {
+ static inline bool store(Storage& storage, option<Storage>&& value) {
if (value) {
storage = std::move(*value);
return true;
}
return false;
}
- template<class Storage, typename Fun, typename T>
- static inline bool fetch(Storage& storage, const Fun& fun, T&& arg) {
- return fetch_(storage, fun(std::forward<T>(arg)));
+ template<typename T>
+ static inline auto fetch(const util::void_type&, T&& arg)
+ -> decltype(std::forward<T>(arg)) {
+ return std::forward<T>(arg);
}
- template<typename Storage, typename T>
- static inline bool fetch(Storage& storage, const util::void_type&, T&& arg) {
- return fetch_(storage, std::forward<T>(arg));
+ template<typename Fun, typename T>
+ static inline auto fetch(const Fun& fun, T&& arg)
+ -> decltype(fun(std::forward<T>(arg))) {
+ return fun(std::forward<T>(arg));
}
static inline bool collect(tdata<>&, const tdata<>&) {
@@ -182,7 +155,7 @@ class projection {
template<class TData, class Trans, typename T0, typename... Ts>
static inline bool collect(TData& td, const Trans& tr,
T0&& arg0, Ts&&... args) {
- return fetch(td.head, tr.head, std::forward<T0>(arg0))
+ return store(td.head, fetch(tr.head, std::forward<T0>(arg0)))
&& collect(td.tail(), tr.tail(), std::forward<Ts>(args)...);
}
View
@@ -43,7 +43,7 @@
#include "cppa/util/at.hpp"
#include "cppa/util/rm_ref.hpp"
#include "cppa/util/void_type.hpp"
-#include "cppa/util/apply_tuple.hpp"
+#include "cppa/util/apply_args.hpp"
#include "cppa/detail/tdata.hpp"
@@ -597,7 +597,7 @@ struct ge_eval_<logical_or_op, Tuple, First, Second> {
template<class Tuple, typename Fun>
struct ge_eval_<exec_xfun_op, Tuple, Fun, util::void_type> {
static inline bool _(const Tuple& tup, const Fun& fun, const util::void_type&) {
- return util::unchecked_apply_tuple<bool>(fun, tup);
+ return util::apply_args(fun, tup, util::get_indices(tup));
}
};
@@ -696,7 +696,7 @@ ge_invoke_any(const guard_expr<OP, First, Second>& ge,
auto x = tuple_cast(tup, cast_token);
CPPA_REQUIRE(static_cast<bool>(x) == true);
ge_invoke_helper<guard_expr<OP, First, Second> > f{ge};
- return util::unchecked_apply_tuple<result_type>(f, *x);
+ return util::apply_args(f, *x, util::get_indices(*x));
}
template<operator_id OP, typename First, typename Second>
@@ -48,6 +48,7 @@ class tpartial_function {
typedef typename util::get_callable_trait<Expr>::type ctrait;
typedef typename ctrait::arg_types ctrait_args;
+ static constexpr size_t num_expr_args = util::tl_size<ctrait_args>::value;
static_assert(util::tl_exists<util::type_list<Args...>,
std::is_rvalue_reference >::value == false,
@@ -77,13 +78,14 @@ class tpartial_function {
tpartial_function(const tpartial_function&) = default;
- //bool defined_at(const typename util::rm_ref<Args>::type&... args) const
bool defined_at(Args... args) const {
return m_guard(args...);
}
result_type operator()(Args... args) const {
- return util::partially_apply<result_type,util::tl_size<ctrait_args>::value>(m_expr, args...);
+ auto targs = std::forward_as_tuple(args...);
+ auto indices = util::get_right_indices<num_expr_args>(targs);
+ return util::apply_args(m_expr, targs, indices);
}
private:
View
@@ -56,29 +56,6 @@ inline auto apply_args_suffxied(F& f, Tuple& tup, util::int_list<Is...>, Args&&.
return f(get_cv_aware<Is>(tup)..., std::forward<Args>(args)...);
}
-template<typename Result, size_t NumFunctorArgs, size_t NumArgs>
-struct partially_apply_helper {
- template<class Fun, typename Arg0, typename... Args>
- static inline Result _(const Fun& fun, Arg0&&, Args&&... args) {
- return partially_apply_helper<Result, NumFunctorArgs, sizeof...(Args)>
- ::_(fun, std::forward<Args>(args)...);
- }
-};
-
-template<typename Result, size_t X>
-struct partially_apply_helper<Result, X, X> {
- template<class Fun, typename... Args>
- static inline Result _(const Fun& fun, Args&&... args) {
- return fun(std::forward<Args>(args)...);
- }
-};
-
-template<typename Result, size_t Num, typename F, typename... Args>
-inline Result partially_apply(F& f, Args&&... args) {
- return partially_apply_helper<Result,Num,sizeof...(Args)>
- ::_(f, std::forward<Args>(args)...);
-}
-
} } // namespace cppa::util
#endif // CPPA_APPLY_ARGS_HPP
Oops, something went wrong.

0 comments on commit 996ab01

Please sign in to comment.