|
-
June 20th, 2002, 08:38 AM
#1
xor
Hi folks. is there an XOR binary (bool,bool) operator in C++ please?
-
June 20th, 2002, 08:49 AM
#2
Presumably you mean logical XOR as opposed to bitwise XOR (the ^ operator).
No. Use:
Code:
(a || b) && !(a && b)
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
June 20th, 2002, 09:37 AM
#3
A better way to do this is :
( a != b ).
This will obviously only be true if one of a and b is TRUE and the other is FALSE.
If you wanted to, you could even define XOR to be !=, as in the following:
#define XOR !=
int main(int argc, char* argv[])
{
bool a = ( false XOR false );
bool b = ( false XOR true );
bool c = ( true XOR false );
bool d = ( true XOR true );
return 0;
}
This approach makes the intention of the code just as clear as an inbuilt xor operator would.
-
June 20th, 2002, 11:50 AM
#4
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|