I'd like to overload operator&&
and operator||
on a custom class, and I'd like for the overloaded operators to obey the short-circuiting behavior of their native counterparts.
I know that there is no mechanism for this in the c++ language, but I'm wondering if perhaps gcc might have some sort of extension that would make this possible. I know that such an extension would cause gcc to violate the official c++ standard, but I see a disclaimer on the gcc documentation that reads, "By default, GCC also provides some additional extensions to the C++ language that on rare occasions conflict with the C++ standard", so it doesn't seem outlandish to ask.
If there is a fundamental reason why such a extension simply could not work, even in theory, that would also be good to know for educational purposes. It feels to me like a short_circuit_inline
keyword that can be used as a drop-in replacement for inline
would have a well-defined meaning and straightforward implementation, but maybe I am wrong.
For what it's worth, I currently have a macro workaround, AND(x,y,...,z)
that does a short-circuited x && y && ... && z
for instances of my custom class. My desire for the operators is somewhat just for cosmetic purposes.