C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Function-bound objects with unary operator %

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Mon, 1 Jun 2026 21:22:32 +0200
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_at_[hidden]> Gesendet:Mo 01.06.2026 20:40 Betreff:Re: [std-proposals] Function-bound objects with unary operator % Anlage:signature.asc An:std-proposals_at_[hidden]; CC:Zhihao Yuan <zy_at_[hidden]>; On Monday, June 1st, 2026 at 7:43 AM, Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> 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_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2026-06-01 19:25:39