Skip to content

Instantly share code, notes, and snippets.

@sean-parent
Created January 25, 2015 22:09
Show Gist options
  • Save sean-parent/39e0f88887d79aff0fc8 to your computer and use it in GitHub Desktop.
Save sean-parent/39e0f88887d79aff0fc8 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <tuple>
#include <utility>
using namespace std;
template <typename F, typename T, size_t... I>
auto apply_(F f, T&& t, integer_sequence<size_t, I...>) {
return f(get<I>(t)...);
}
template <typename F, typename... Args>
auto apply(F f, tuple<Args...>&& t) {
return apply_(f, t, make_integer_sequence<size_t, sizeof...(Args)>());
}
int main() {
apply([](auto x, auto y, auto z) {
cout << x << ", " << y << ", " << z << endl;
}, make_tuple(10, "Hello", 42.5));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment