C++ Logo

std-proposals

Advanced search

Re: [std-proposals] if !(condition)

From: Yexuan Xiao <bizwen_at_[hidden]>
Date: Sat, 20 Apr 2024 18:51:43 +0000
I completely understand if you think this issue is too minor, but the libc++ example demonstrates that it eliminates some operator precedence issues, and the previous proposal P1181 was invented with different motivations, which might change your perspective.

With C++23 introducing if ! consteval, I believe it’s appropriate to introduce ! to regular if statements, as it doesn’t sacrifice consistency.
________________________________
From: Tiago Freire <tmiguelf_at_[hidden]>
Sent: Sunday, April 21, 2024 2:33
To: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
Cc: Yexuan Xiao <bizwen_at_[hidden]>
Subject: RE: if !(condition)


My opinion on this is that it is too small to matter.

The only use case is, when you have a whole negation of the condition and that is the only branch, it doesn’t allow you to do anything that you can’t already do as it is.

It sacrifices a little bit of syntax consistency and the only thing you get in return is to save 2 parentheses.

Doesn’t look like it could harm, but also doesn’t look like it does much for me either. It’s a big meh.

That the pattern if(!()) occurs often doesn’t convince me as sufficient reason.

My 2c



From: Std-Proposals <std-proposals-bounces_at_[hidden]> On Behalf Of Yexuan Xiao via Std-Proposals
Sent: Saturday, April 20, 2024 18:10
To: std-proposals_at_[hidden]
Cc: Yexuan Xiao <bizwen_at_[hidden]>
Subject: [std-proposals] if !(condition)



I've wrote a proposal that suggests allowing the omission of the outermost parentheses to simplify the conditions in if statements:

https://storage.nykz.org/proposals/if-not/



Please share your comments.

Received on 2024-04-20 18:51:49