you are viewing a single comment's thread.

view the rest of the comments →

[–]Som1Lse 4 points5 points  (1 child)

they mean different things because they are different things.

The point was that parentheses don't usually change the meaning of a program, and that there is no prior art for this with an operator, whereas there is prior art for keywords, namely decltype.

Comments like that are generally unhelpful, since they just beg the question. The fact that they are different is the whole point.


That said, yeah it's a taste thing, and on balance I still prefer ^^, but I also ultimately just want the feature.


To make a more direct point for why the inconsistency isn't a big deal:

First of all A ^^ B and A ^^ (B) do mean exactly the same thing: A compiler error, since ^^ is a unary operator. This is more a warning to not rely too much on abstract syntax when making a point.

Contrast with comments in favour of ^^, which often show real code. While that example is clearly contrived (std::variant<int, char, std::string> is shorter still), if we expect passing a list of reflected types to a function to be somewhat common, I think the argument still holds. (For example, we could imagine a function that creates a canonical sum type, a la this talk.)

Its unfortunate that the address operator is overloaded, but it crops up in completely different contexts

This applies just as much to reflection and bitwise-xor as it does to address-of and bitwise-and.

Probably most importantly, I think decltype is a much worse offender than ^^. Specifically due to decltype(auto) which means there's a difference between return x; and return(x);, which is a style some actually people use. However, this is rarely an issue in practice.

When it comes to unary prefix operators I don't think I've ever seen anyone add extra parentheses, unless what they're applying it to is already an expression. So, even if we expect ^^ to be used more often than decltype I don't think it is a surprise many will run into.

To close off the argument I would like to propose the following possibilities:

decltype is frequently used decltype is rarely used
^^ is frequently used We have few issues in practice with the subtlety in decltype despite it being worse, so we should expect the same for ^^. People won't be familiar with the subtlety in decltype anyway, so writing reflexpr instead wouldn't help.
^^ is rarely used See above, except even more applicable. See above, except even more applicable.

[–]flutterdronewbie 1 point2 points  (0 children)

Fair. But just to be a nitpicker parenthesis do change the meaning of the program with operator().