fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4.  
  5. // Some preparation
  6.  
  7. class die
  8. {
  9. public:
  10. die(const char *message) : m_message(message) {}
  11. const char *message() const { return m_message; }
  12. private:
  13. const char *m_message;
  14. };
  15.  
  16. template <class T> T operator ||(const T &t, const die &d)
  17. {
  18. if (t)
  19. return t;
  20. std::cerr << d.message() << std::endl;
  21. exit(1);
  22. }
  23.  
  24. // And now some fun
  25.  
  26. class Test { };
  27.  
  28. int badFunction() { return 0; }
  29.  
  30. int main()
  31. {
  32. Test *p = new Test() || die("Can't allocate object");
  33. int x = badFunction() || die("0 returned");
  34. return 0;
  35. }
  36.  
Runtime error #stdin #stdout 0.01s 2808KB
stdin
Standard input is empty
stdout
Standard output is empty