Guest User

Untitled

a guest
Jan 22nd, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <functional>
  4. #include <tuple>
  5.  
  6. using namespace std;
  7.  
  8. template <typename... TArgs>
  9. void cast_apply(function<void()> fn, tuple<TArgs...> tup) {
  10. function<void(TArgs...)> realFn = *reinterpret_cast<function<void(TArgs...)>*>(&fn);
  11. apply(realFn, tup);
  12. }
  13.  
  14. int main() {
  15. int foo = 10;
  16. function<void(int, int, string)> fn = [&foo](int a, int b, string c) {
  17. cout << "foo=" << foo << endl;
  18. cout << "a=" << a << endl;
  19. cout << "b=" << b << endl;
  20. cout << "c=" << c << endl;
  21. };
  22. fn(1, 2, "first");
  23. cout << "---" << endl;
  24.  
  25. function<void()> opaque = *reinterpret_cast<function<void()>*>(&fn);
  26. auto tup = make_tuple(42, 69, string("second"));
  27. foo = 9001;
  28. cast_apply(opaque, tup);
  29. return 0;
  30. }
Add Comment
Please, Sign In to add comment