Logical xor operator in c++?
- by RAC
Is there such a thing? First time I encountered a practical need for it, but I don't see one listed in stroustrup. I intend to write:
// Detect when exactly one of A,B is equal to five.
return (A==5) ^^ (B==5);
But there is no ^^ operator. Can I use bitwise ^ here and get the right answer (regardless of machine representation of true and false)? I never mix & and &&, or | and ||, so I hesitate to do that with ^ and ^^.
I'd be more comfortable writing my own "bool XOR(bool,bool)" function instead.