C++ Logo

std-proposals

Advanced search

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

From: Yexuan Xiao <bizwen_at_[hidden]>
Date: Sat, 20 Apr 2024 18:30:08 +0000
I acknowledge that placing a `!` after `if` may not be ideal when there is an initialization statement separate from the condition—especially if the initialization statement is lengthy. So I do not plan to add it to `for` statements. I intend for the structure as a whole with `if !` or `if not`, rather than just adding `!` in front of parentheses. Regardless, it indeed simplifies superfluous parentheses, and perhaps people will get used to it once it becomes widely accepted.

Moreover, the core appeal of the previous similar proposal, P1181, is that it allows for the easy use of the nagation of the condition when the initialization statement is the condition itself. Overall, I believe allowing an initialization statement is not harmful.

The reason for the placement of constexpr afterwards is also because I want to treat `if !` or `if not` as a whole, rather than separate them.

________________________________
From: Std-Proposals <std-proposals-bounces_at_[hidden]> on behalf of Jason McKesson via Std-Proposals <std-proposals_at_[hidden]>
Sent: Sunday, April 21, 2024 1:55
To: std-proposals_at_[hidden]p.org <std-proposals_at_[hidden]>
Cc: Jason McKesson <jmckesson_at_[hidden]>
Subject: Re: [std-proposals] if !(condition)

On Sat, Apr 20, 2024 at 12:09 PM Yexuan Xiao via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> I've wrote a proposal that suggests allowing the omission of the outermost parentheses to simplify the conditions in if statements:
> https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstorage.nykz.org%2Fproposals%2Fif-not%2F&data=05%7C02%7C%7C6f1127b22aa549a37b2308dc6163153f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638492325404575880%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=ABD27MDIISnQGQi%2BJxuV4fw9y%2B7yCXP2gRuO86YNyuM%3D&reserved=0<https://storage.nykz.org/proposals/if-not/>
>
> Please share your comments.

I really don't like that you can put an initializer statement inside
of the `!` parentheses. That can put a lot of distance between the
negation and the expression being negated. If `if!` is going to be a
thing, it shouldn't be able to be used with initializers. If you add
an initializer, just put the negation with the expression where it
belongs.

Similarly, I think `constexpr` should come before the `!`, not after.
--
Std-Proposals mailing list
Std-Proposals_at_[hidden]
https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.isocpp.org%2Fmailman%2Flistinfo.cgi%2Fstd-proposals&data=05%7C02%7C%7C6f1127b22aa549a37b2308dc6163153f%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638492325404584348%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=rU04FaSLLCguamvwj7EMzHYPy%2FJi%2Fwl06YJl%2BKW89RY%3D&reserved=0<https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals>

Received on 2024-04-20 18:30:17