That is quite dangerous for dead locks and not locked accesses. If you need it, then use std::optional
-----Ursprüngliche Nachricht-----
Von: Zhihao Yuan via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Mo 01.06.2026 20:40
Betreff: Re: [std-proposals] Function-bound objects with unary operator %
Anlage: signature.asc
An: std-proposals@lists.isocpp.org;
CC: Zhihao Yuan <zy@miator.net>;
On Monday, June 1st, 2026 at 7:43 AM, Frederick Virchanza Gotham via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
> So what is this feature good for? Well you can spontaneously lock a
> mutex at any point in a function:
>
> void Func(void)
> {
> if ( a )
> {
> if ( b )
> {
> if ( c )
> {
> %lock_guard{ my_global_mutex };
> }
> }
> }
>
> DoSomething();
> }
>
Python standard library offers an
ExitStack to address the demand.
The benefit of ExitStack is that,
since it creates yet another
variable, you can designate which
scope your `%` binds to. Maybe
you can repurpose goto labels for
this, but a library solution still
looks more powerful.
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
_______________________________________________
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals