fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. typedef void (*F)();
  5.  
  6. template<F f> struct Goal
  7. {
  8. Goal() { f(); }
  9. };
  10.  
  11. template<F f> struct Singleton
  12. {
  13. static Goal<f> instance;
  14. Singleton() { (void)(&instance); }
  15. };
  16. template<F f> Goal<f> Singleton<f>::instance;
  17.  
  18. void foo() { cout << "foo" << endl; }
  19. void bar() { cout << "bar" << endl; }
  20.  
  21. int main() {
  22. Singleton<bar> tmp;
  23. return 0;
  24. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
bar