Created
June 21, 2015 17:08
-
-
Save hatsusato/da161b1be86e5c661cf4 to your computer and use it in GitHub Desktop.
unpack tuple and apply them to a function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <tuple> | |
#include <type_traits> | |
#include "integer_sequence.hpp" | |
template <typename T> | |
using resultof = typename std::result_of<T>::type; | |
template <typename F, typename... Args, size_t... I> | |
auto apply_(F&& f, std::tuple<Args...>&& args, IntegerSeq<I...>) | |
-> resultof<F(Args...)> { | |
using T = std::tuple<Args...>; | |
return f(std::get<I>(std::forward<T>(args))...); | |
} | |
template <typename F, typename... Args> | |
auto apply(F&& f, std::tuple<Args...>&& args) -> resultof<F(Args...)> { | |
using T = std::tuple<Args...>; | |
using S = MakeSeq<sizeof...(Args)>; | |
return apply_(std::forward<F>(f), std::forward<T>(args), S()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment