mattkretz / wg21-papers

my papers to WG21 — the C++ committee
5 stars 7 forks source link

Return type of `where_expression::operator++/--` #14

Closed mattkretz closed 7 years ago

mattkretz commented 7 years ago

@jensmaurer:

(24) For where_expression, it's surprising that op++ and op-- return values. It's surprising to operator on a full datapar here: vec2 = where(m, vec)++; It's ok not to support that; then the return type should be void to prevent the bug.

Hmm, I don't recall why I deviated from void with increment and decrement. Probably because of the difference of pre-/post-increment. There would be no difference if the return type is void. But maybe that's for the better anyway.

If inc-/decrement return void, do you think I should drop post-dec/inc? I think not.

jensmaurer commented 7 years ago

Here's my thinking:

++where(m, vec) should return where(m,vec) where(m,vec)++ should return void (or, alternatively, something like where(m, copy-of-vec), but that's a strange beast, because "where" doesn't copy the datapar). So, the postfix operators are just cosmetics compared to the prefix operators, but some people might like postfix rather than prefix. So, let's keep them.

mattkretz commented 7 years ago

But ++x is semantically the same as x += 1, no? The latter returns void for where expressions. I'd have both return void and thus have pre and post be equivalent. It's the most conservative approach that is easiest to improve upon when going from TS to IS.

jensmaurer commented 7 years ago

Fine with me. My point is that an operation on a where-expression (or a result thereof) should never magically drop the mask.

mattkretz commented 7 years ago

Good. Since my expectation would be a reference to the vector (i.e. to drop the mask), this proves my point that it must return void. It's too ambiguous.