Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <functional>
- #include <tuple>
- using namespace std;
- template <typename... TArgs>
- void cast_apply(function<void()> fn, tuple<TArgs...> tup) {
- function<void(TArgs...)> realFn = *reinterpret_cast<function<void(TArgs...)>*>(&fn);
- apply(realFn, tup);
- }
- int main() {
- int foo = 10;
- function<void(int, int, string)> fn = [&foo](int a, int b, string c) {
- cout << "foo=" << foo << endl;
- cout << "a=" << a << endl;
- cout << "b=" << b << endl;
- cout << "c=" << c << endl;
- };
- fn(1, 2, "first");
- cout << "---" << endl;
- function<void()> opaque = *reinterpret_cast<function<void()>*>(&fn);
- auto tup = make_tuple(42, 69, string("second"));
- foo = 9001;
- cast_apply(opaque, tup);
- return 0;
- }
Add Comment
Please, Sign In to add comment