Why is it not possible to overload the ternary operator \' ?: \'?
I use the ternary operator often to consolidate if statements, and am curious why the language desi
I think the main reason at the time that it didn't seem worth
the effort of inventing a new syntax just for that operator.
There is no token ?:
, so you'd have to create a number of
special grammar rules just for it. (The current grammar rule
has operator
followed by an operator, which is a single
token.)
As we've learned (from experience) to use operator overloading
more reasonably, it has become apparent that we really shouldn't
have allowed overloading of &&
and ||
either, for the
reasons other responses have pointed out, and probably not
operator comma as well (since the overloaded versions won't have
the sequence point which the user expects). So the motivation
to support it is even less than it was originally.