fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Block
  5. {
  6. public:
  7. Block(const char* name) :
  8. name(name)
  9. {
  10. cout << "start: " << name << endl;
  11. }
  12. operator bool()
  13. {
  14. return false;
  15. }
  16. ~Block()
  17. {
  18. cout << "end: " << name << endl;
  19. }
  20. private:
  21. const char* name;
  22. };
  23.  
  24. #define BLOCK(name) if(Block block = name) ; else
  25.  
  26. int main()
  27. {
  28. BLOCK("Program started")
  29. {
  30. if (1) BLOCK("if (1)")
  31. {
  32. cout << "Starting loop now\n";
  33.  
  34. for (int i = 0; i < 3; i++) BLOCK("Iteration")
  35. {
  36. cout << "Executing iteration " << i << "\n";
  37. }
  38. cout <<"Condition execution complete\n";
  39. }
  40. }
  41. }
Success #stdin #stdout 0s 3464KB
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