Obviously, you need a flexible solution that can support masquerading types like boolean. To do this, the following is allowed:
template<typename T> bool Flip(const T& t);
Then you can specialize in different types that may look like booleans. For example:
template<> bool Flip<bool>(const bool& b) { return !b; } template<> bool Flip<int>(const int& i) { return !(i == 0); }
An example of using this design:
if(Flip(false)) { printf("flipped false\n"); } if(!Flip(true)) { printf("flipped true\n"); } if(Flip(0)) { printf("flipped 0\n"); } if(!Flip(1)) { printf("flipped 1\n"); }
No, I'm not serious.
dma Mar 04 '09 at 17:14 2009-03-04 17:14
source share