Skip to content

Instantly share code, notes, and snippets.

@XeCycle
Created December 31, 2015 01:29
Show Gist options
  • Save XeCycle/9c0604ed82edc4c04819 to your computer and use it in GitHub Desktop.
Save XeCycle/9c0604ed82edc4c04819 to your computer and use it in GitHub Desktop.
apply a tuple of parameters to a function
namespace tuple_util_impl {
template <size_t... i, class Function, class Tuple>
auto spread_call(std::index_sequence<i...>, Function f, Tuple&& t)
-> decltype(f(std::get<i>(t)...))
{
return f(std::get<i>(t)...);
}
} // namespace tuple_util_impl
template <class Function, class Tuple>
auto spread_call(Function&& f, Tuple&& t) -> decltype(
tuple_util_impl::spread_call(
std::make_index_sequence<std::tuple_size<typename std::decay<Tuple>::type>::value>(),
f, t))
{
return tuple_util_impl::spread_call(
std::make_index_sequence<std::tuple_size<typename std::decay<Tuple>::type>::value>(),
std::forward<Function>(f), std::forward<Tuple>(t));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment