🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c++
Article #1004

Re: A better experimental::scope_exit

#1004
From: Bonita Montero
Date: Mon, 23 Nov 2026 14:00
33 lines
2780 bytes
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.

> If you want to claim your solution is "better", start with an example or 
> two showing what you can do with your version, that cannot be done with 
> standard or common versions.  At the moment, all you have done is shown 
> how you can add an apparently pointless "Dependent" function that must 
> have a "run" method. ...

You can see from the code for what the dependent is good for.
And even more from the static_assert in the private part of the class.

> And if you are going to require the use of C++20 or concepts (not a bad
> idea), then at least use them consistently - put the concepts where they
> belong, restricting the types of the template, rather than in static
> assertions.  And drop the C-style "assert" for something that is known
> at compile time.

I liked concepts until I realized that they make the code less redable
than the way I did it.
Technical Details
Message-ID: <11e1gtl$1u1jq$1@raubtier-asyl.eternal-september.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
References: <11dsk17$8ske$2@raubtier-asyl.eternal-september.org> <11e1bd7$1rqma$1@dont-email.me>

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!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita Montero <Bonita.Montero@gmail.com>
Newsgroups: comp.lang.c++
Subject: Re: A better experimental::scope_exit
Date: Mon, 23 Nov 2026 15:00:22 +0100
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <11e1gtl$1u1jq$1@raubtier-asyl.eternal-september.org>
References: <11dsk17$8ske$2@raubtier-asyl.eternal-september.org>
 <11e1bd7$1rqma$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 23 Nov 2026 14:00:22 +0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org;
	logging-data="2033274"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/Xh0pjhONnMF2GnFtoy1lWZQulh1wgmSk="; posting-host="6d91dc74f77a8fc154aca66c0d8ca15e"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:RIMXEU+qCBLDp16MMGkPYPhBvjY= sha256:iLfXtpQbCcti+zqEW4J/sDJkij0ixQ4rjrjCRXo0T8w=
	sha1:Mv7UiCkCyNKSZs6VUtfpTER8JPw= sha256:stKJgTL08Iw/KQFnjZnBplk/GgK60mfcQnyuqfXxXXQ=
In-Reply-To: <11e1bd7$1rqma$1@dont-email.me>
Content-Language: de-DE