Article View: comp.lang.c++
Article #1006Re: A better experimental::scope_exit
From: David Brown
Date: Mon, 23 Nov 2026 14:19
Date: Mon, 23 Nov 2026 14:19
24 lines
2320 bytes
2320 bytes
On 23/11/2026 15:00, Bonita Montero wrote:
> Am 23.11.2026 um 13:26 schrieb David Brown:
>
>> template<typename T>
>> struct scope_exit {
>> T f;
>> scope_exit(T f) : f(f) { }
>> ~scope_exit() { f(); }
>> };
>
> You can't cascade multiple exits with that. This means if you have
> several manipulations on a data structure and you want to revert them
> if an exception occurs the destructor revers the changes so far. But
> if nothing happens in that sense you simply call .disable() on the
> last node in the chain and all dependent nodes are also disabled.
> Just as a commit in a databse.
>
That is not an example - it's a vague idea of an imagined use-case. Try
showing an example, using your scope_exit. Compare it with
alternatives. Then we will be able to see if and why your code is
better, and also get an idea whether it would be better to have it in
addition to normal scope_exit features, rather than instead of them.
Technical Details
Message-ID:
<11e1i1q$1ugou$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11dsk17$8ske$2@raubtier-asyl.eternal-september.org> <11e1bd7$1rqma$1@dont-email.me> <11e1gtl$1u1jq$1@raubtier-asyl.eternal-september.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.lang.c++ Subject: Re: A better experimental::scope_exit Date: Mon, 23 Nov 2026 15:19:37 +0100 Organization: A noiseless patient Spider Lines: 24 Message-ID: <11e1i1q$1ugou$1@dont-email.me> References: <11dsk17$8ske$2@raubtier-asyl.eternal-september.org> <11e1bd7$1rqma$1@dont-email.me> <11e1gtl$1u1jq$1@raubtier-asyl.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Mon, 23 Nov 2026 14:19:39 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2048798"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/UtqBAQQNVVWbT9y+eyhE4SuTl6xJfZqc="; posting-host="4c393d4ea759cbe76e4062837f9f8a62" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:0+tYNUrO97Q1ZLt4qhOvJ6M/2MU= sha256:+0YfUIAxA9/at3InCJ7fqzev+kfqf8Pr+OAS8CL8kDs= sha1:QqqU3c+IPkr3T8S13HN+GnSa8Lo= sha256:Qaoka9I4+vyrdhjIP0cJcK62Ssj678DdaAf8O+LX/44= Content-Language: en-GB, nb-NO In-Reply-To: <11e1gtl$1u1jq$1@raubtier-asyl.eternal-september.org>