C++ Logo

std-proposals

Advanced search

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

From: Yexuan Xiao <bizwen_at_[hidden]>
Date: Sat, 20 Apr 2024 17:08:44 +0000
Regarding the issue you pointed out, I have the following point:

Overloading ! is rare, and using it as a condition in an if statement is even rarer, strange, and potentially dangerous. I believe that excessive consideration of it is not beneficial. Furthermore, my choice is to convert the condition to a bool first and then negate it. I think this approach more natural, as the ! character does not directly combine with conditions.

Later, I will update my proposal by incorporating P1180 and your comment.
________________________________
From: Jan Schultke <janschultke_at_[hidden]>
Sent: Sunday, April 21, 2024 0:31
To: std-proposals_at_[hidden] <std-proposals_at_[hidden]>
Cc: Yexuan Xiao <bizwen_at_[hidden]>
Subject: Re: [std-proposals] if !(condition)

"if not" has been proposed before and rejected, albeit with a
different motivation:
https://aus01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2018%2Fp1181r0.html&data=05%7C02%7C%7C2b9d59e85fd34f54fe7308dc615766d4%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638492275252911783%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=OpN4Tf91QLp4szKY%2FQNPBFSyx5%2FOGUE3wjp01i4a9%2Fc%3D&reserved=0<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1181r0.html>

The main issue here is whether it should behave exactly as if the
parentheses were omitted, or whether it should behave like "if (...)
{} else { ... }". Whether the "!" is actually applied here makes a
difference for types with an overloaded ! operator, such as tri-bool.

Since there is significant complication to the language and the
benefit is extremely minor, such "if not" proposals don't make much
sense.


Received on 2024-04-20 17:08:51