fork download
  1. #include <iostream>
  2. using std::cout;
  3. using std::endl;
  4.  
  5. class my_bool {
  6. private:
  7. bool value;
  8. public:
  9. my_bool(bool value) : value(value) {}
  10. explicit operator bool() { return value; };
  11.  
  12. friend my_bool operator==(const my_bool & instance_1, const my_bool & instance_2) {
  13. return instance_1.value == instance_2.value;
  14. }
  15. friend my_bool operator&&(const my_bool & instance_1, const my_bool & instance_2) {
  16. cout << "FOOOOOOOOO bar" << endl;
  17. return instance_1.value && instance_2.value;
  18. }
  19. friend my_bool operator&&(const my_bool & lhs, bool rhs) {
  20. return lhs && my_bool(rhs);
  21. }
  22. friend my_bool operator&&(bool lhs, const my_bool & rhs) {
  23. return my_bool(lhs) && rhs;
  24. }
  25.  
  26. };
  27.  
  28. int main(int, char **){
  29. my_bool a = true;
  30. bool b = false;
  31.  
  32. if(a == b){
  33. // do something
  34. }
  35.  
  36. if(b && a){
  37. // do something
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
FOOOOOOOOO bar