fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3. #include <vector>
  4. #include <functional>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. template< typename T>
  10. void X() {
  11. cout<<typeid(T).name()<<endl;
  12. }
  13.  
  14.  
  15. struct A {
  16.  
  17.  
  18. vector< function<void(void)> > callbacks;
  19.  
  20. void z() {
  21. for( auto a : callbacks ) a();
  22. }
  23.  
  24. template<typename T>
  25. void M() {
  26. callbacks.push_back( [](){ X<T>();} );
  27. }
  28.  
  29. };
  30.  
  31. int main() {
  32. A a;
  33. a.M<int>();
  34. a.M<double>();
  35. a.M<string>();
  36. a.z();
  37. return 0;
  38. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
i
d
Ss