Commit 46bb1ed7 authored by Alexander Shaposhnikov's avatar Alexander Shaposhnikov Committed by facebook-github-bot-4

[folly] Enable support of applyTuple for const tuples

Summary: This diff fixes the helper template ReturnValue to enable using of applyTuple with
constant refs.

Reviewed By: @ot, @ddrcoder

Differential Revision: D2284733
parent c3e2a712
...@@ -91,7 +91,7 @@ struct CallTuple { ...@@ -91,7 +91,7 @@ struct CallTuple {
// The point of this meta function is to extract the contents of the // The point of this meta function is to extract the contents of the
// tuple as a parameter pack so we can pass it into std::result_of<>. // tuple as a parameter pack so we can pass it into std::result_of<>.
template<class F, class Args> struct ReturnValue {}; template<class F, class Args> struct ReturnValue;
template<class F, class ...Args> template<class F, class ...Args>
struct ReturnValue<F,std::tuple<Args...>> { struct ReturnValue<F,std::tuple<Args...>> {
typedef typename std::result_of<F (Args...)>::type type; typedef typename std::result_of<F (Args...)>::type type;
...@@ -104,12 +104,12 @@ struct ReturnValue<F,std::tuple<Args...>> { ...@@ -104,12 +104,12 @@ struct ReturnValue<F,std::tuple<Args...>> {
template<class Callable, class Tuple> template<class Callable, class Tuple>
typename detail::ReturnValue< typename detail::ReturnValue<
typename std::decay<Callable>::type, typename std::decay<Callable>::type,
typename std::remove_reference<Tuple>::type typename std::decay<Tuple>::type
>::type >::type
applyTuple(const Callable& c, Tuple&& t) { applyTuple(const Callable& c, Tuple&& t) {
typedef typename detail::ReturnValue< typedef typename detail::ReturnValue<
typename std::decay<Callable>::type, typename std::decay<Callable>::type,
typename std::remove_reference<Tuple>::type typename std::decay<Tuple>::type
>::type RetT; >::type RetT;
return detail::CallTuple<RetT>::call(c, std::forward<Tuple>(t)); return detail::CallTuple<RetT>::call(c, std::forward<Tuple>(t));
} }
......
...@@ -86,7 +86,7 @@ struct GuardObj : GuardObjBase { ...@@ -86,7 +86,7 @@ struct GuardObj : GuardObjBase {
: f_(std::move(f)) : f_(std::move(f))
, args_(std::move(args)) , args_(std::move(args))
{} {}
GuardObj(GuardObj&& g) GuardObj(GuardObj&& g) noexcept
: GuardObjBase(std::move(g)) : GuardObjBase(std::move(g))
, f_(std::move(g.f_)) , f_(std::move(g.f_))
, args_(std::move(g.args_)) , args_(std::move(g.args_))
...@@ -163,4 +163,6 @@ TEST(ApplyTuple, Test) { ...@@ -163,4 +163,6 @@ TEST(ApplyTuple, Test) {
Mover m; Mover m;
folly::applyTuple(move_only_func, folly::applyTuple(move_only_func,
std::forward_as_tuple(std::forward<Mover>(Mover()))); std::forward_as_tuple(std::forward<Mover>(Mover())));
const auto tuple3 = std::make_tuple(1, 2, 3.0);
folly::applyTuple(func, tuple3);
} }
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