Skip to content

Instantly share code, notes, and snippets.

@hatsusato
Created June 21, 2015 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hatsusato/da161b1be86e5c661cf4 to your computer and use it in GitHub Desktop.
Save hatsusato/da161b1be86e5c661cf4 to your computer and use it in GitHub Desktop.
unpack tuple and apply them to a function
#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