fork(1) download
  1. #include <iostream>
  2.  
  3. void callback( int i )
  4. {
  5. std::cout << __PRETTY_FUNCTION__ << " -> " << i << '\n';
  6. }
  7.  
  8. struct Callback
  9. {
  10. void operator() (int i )
  11. {
  12. std::cout << __PRETTY_FUNCTION__ << " -> " << i << '\n';
  13. }
  14. };
  15.  
  16. template< typename Func >
  17. void do_callback( Func f, int i)
  18. {
  19. std::cout << __PRETTY_FUNCTION__ << " -> ";
  20. f(i);
  21. }
  22.  
  23. int main()
  24. {
  25. do_callback( callback, 1 );
  26. do_callback( &callback, 2 );
  27. do_callback( Callback(), 3 );
  28. do_callback( []( int i ){ std::cout << __PRETTY_FUNCTION__ << " -> " << i << '\n'; }, 4 );
  29. }
Success #stdin #stdout 0s 2828KB
stdin
Standard input is empty
stdout
void do_callback(Func, int) [with Func = void (*)(int)] -> void callback(int) -> 1
void do_callback(Func, int) [with Func = void (*)(int)] -> void callback(int) -> 2
void do_callback(Func, int) [with Func = Callback] -> void Callback::operator()(int) -> 3
void do_callback(Func, int) [with Func = main()::<lambda(int)>] -> main()::<lambda(int)> -> 4