Skip to content

Commit

Permalink
[Misc] Fixed tuple::invoke() for lambdas.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Sibiryov committed Apr 1, 2015
1 parent bbc3bf0 commit 9a7e92b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion include/cocaine/rpc/slot/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct function_slot:

R
call(tuple_type&& args) const {
return tuple::invoke(callable, std::move(args));
return tuple::invoke(std::move(args), callable);
}

private:
Expand Down
30 changes: 9 additions & 21 deletions include/cocaine/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,10 @@ template<size_t... Indices>
struct invoke_impl<index_sequence<Indices...>> {
template<class F, typename... Args>
static inline
typename result_of<F>::type
apply(F&& callable, std::tuple<Args...>&& args) {
return callable(std::get<Indices>(args)...);
}

template<class F, typename... Args>
static inline
typename result_of<F>::type
apply(const F& callable, std::tuple<Args...>&& args) {
auto
apply(std::tuple<Args...>&& args, F&& callable)
-> decltype(callable(std::declval<Args>()...))
{
return callable(std::get<Indices>(args)...);
}
};
Expand All @@ -92,20 +87,13 @@ struct fold {

template<class F, typename... Args>
inline
typename result_of<F>::type
invoke(F&& callable, std::tuple<Args...>&& args) {
return aux::invoke_impl<
typename make_index_sequence<sizeof...(Args)>::type
>::apply(std::move(callable), std::move(args));
}

template<class F, typename... Args>
inline
typename result_of<F>::type
invoke(const F& callable, std::tuple<Args...>&& args) {
auto
invoke(std::tuple<Args...>&& args, F&& callable)
-> decltype(callable(std::declval<Args>()...))
{
return aux::invoke_impl<
typename make_index_sequence<sizeof...(Args)>::type
>::apply(callable, std::move(args));
>::apply(std::move(args), std::forward<F>(callable));
}

}} // namespace cocaine::tuple
Expand Down
4 changes: 2 additions & 2 deletions src/service/node/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class app_service_t:
boost::optional<std::shared_ptr<const dispatch_type>>
operator()(tuple_type&& args, upstream_type&& upstream) {
return tuple::invoke(
std::bind(&app_service_t::enqueue, parent, std::ref(upstream), ph::_1, ph::_2),
std::move(args)
std::move(args),
std::bind(&app_service_t::enqueue, parent, std::ref(upstream), ph::_1, ph::_2)
);
}

Expand Down

0 comments on commit 9a7e92b

Please sign in to comment.