C++ Logo

std-proposals

Advanced search

Re: [std-proposals] 回复: 回复: A Proposal about A New Keyword assure

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sun, 1 Jun 2025 13:45:17 -0400
On Sun, Jun 1, 2025 at 12:41 PM SD SH via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Optimization for caller and not for callee.

So, what you want is for `contract_assert` to be an expression (or
expression-like, since it's not actually an expression) rather than a
statement. This:

```
sqrt(d assure(d >= 0))
```

Is exactly equivalent to:

```
contract_assert(d >= 0);
sqrt(d);
```

Personally, I prefer the latter, as it removes unneeded visual noise
from the function call. It also makes it much more clear that the
assert applies to more than just that one expression.

Received on 2025-06-01 17:45:29