Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Why couldn't `?` be parsed as half an operator and `:` as the other half?

Because the language defines it to be an atomic operator named "conditional operator." As to the implications of that definition, please read the referenced link[0].

> In fact, I'd argue that the only reason this might seem seem like a rule is that almost all of the other operators in common use are either unary or binary, making it easy to use a single token for the operator itself.

It is "a rule" because that is how the language is defined. If you'd like to argue otherwise, please feel free to do so with the C++ standards committee.

0 - https://en.cppreference.com/w/cpp/language/operator_other



From what I can tell, the link doesn't seem to disagree with me? The quote I was responding two characterized `?` and `:` as separate operators, and I argued that they were in fact one operator with two separate syntax tokens. The link you provided describes `?` and `:` as a single operator, which is consistent with what I said. I suspect that the C++ standard doesn't disagree with me that half of two is one, which would mean that `?` is half of the operator, and `:` is the other half.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: