fork download
  1.  
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6.  
  7. template<class T>
  8. void start_block(const char* str, T f)
  9. {
  10. cout<<"start: "<<str<<endl;
  11. f();
  12. cout<<"end: "<<str<<endl;
  13. }
  14. #define BLOCK(x) start_block(x,[&]
  15.  
  16. int main()
  17. {
  18.  
  19. BLOCK("Program started")
  20. {
  21. if (1) BLOCK("if (1)")
  22. {
  23. cout << "Starting loop now\n";
  24.  
  25. for (int i = 0; i < 3; i++) BLOCK("Iteration")
  26. {
  27. cout << "Executing iteration " << i << "\n";
  28. });
  29.  
  30. cout <<"Condition execution complete\n";
  31. });
  32. });
  33.  
  34. return 0;
  35. }
  36.  
  37.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
start: Program started
start: if (1)
Starting loop now
start: Iteration
Executing iteration 0
end: Iteration
start: Iteration
Executing iteration 1
end: Iteration
start: Iteration
Executing iteration 2
end: Iteration
Condition execution complete
end: if (1)
end: Program started