| ▲ | akoboldfrying 2 days ago | |||||||||||||
Reminds me of an idea I had years ago, for implementing "named binary operator syntax" in C++ so that stuff like the following would work:
The basic trick was to notice that this is really parsed as:
which you could implement with (roughly):
But I sat on this for a while and later discovered someone else had already come up with it :-/EDIT: Thanks commenter hawkice for fixing my XOR arithmetic! | ||||||||||||||
| ▲ | Someone 2 days ago | parent | next [-] | |||||||||||||
Neat trick, but for binary logical operations, C++ already has alternative tokens. See https://en.cppreference.com/cpp/language/operator_alternativ... | ||||||||||||||
| ▲ | gettingoverit 2 days ago | parent | prev | next [-] | |||||||||||||
Yeah, I've first seen it over 15 years ago. Usually you use operator of the same priority as you'd like, and also #define xor &xor_i& to get all that detail out of sight. | ||||||||||||||
| ▲ | hawkice 2 days ago | parent | prev [-] | |||||||||||||
This couldn't possibly matter, but 5 xor 3 is 6. | ||||||||||||||
| ||||||||||||||