Skip to content

Commit

Permalink
testing custom operator&&
Browse files Browse the repository at this point in the history
  • Loading branch information
albertz committed Apr 5, 2012
1 parent 0b65ab9 commit 19a603a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cpp_custom_andop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>
#include <string>
using namespace std;

struct B {};
B operator&&(bool a, const B& b) { return B(); }
B f(const std::string& s) { cout << s << endl; }

struct C {
C(bool) {}
operator bool() const { return true; }
};
C operator&&(bool a, const C& b) { if(a) return b; return a; }
C g(const std::string& s) { cout << s << endl; }


int main() {
true && f("f1");
false && f("f2");

if(true && g("g1")) {}
if(false && g("g2")) {}
}

0 comments on commit 19a603a

Please sign in to comment.