Created
January 25, 2015 22:09
-
-
Save sean-parent/39e0f88887d79aff0fc8 to your computer and use it in GitHub Desktop.
This file contains 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 <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