Article View: comp.lang.c++
Article #1001Re: A better experimental::scope_exit
From: Tristan Wibberley
Date: Mon, 23 Nov 2026 09:41
Date: Mon, 23 Nov 2026 09:41
64 lines
3953 bytes
3953 bytes
On 21/11/2026 17:22, Bonita Montero wrote:
template<[...]>
struct defer final
{
defer( [...] ) : [...]
{
assert(std::is_void_v<Dependent> || pDep);
}
On the irregularity of that constraint
======================================
A little excess irregularity, I feel; why not provide a static instance
of "empty" which can be used to terminate the list of deps then provide
an explicit template specialisation for the sugar of using "void"?
Furthermore "assert" is a bit risky because it's /always/ invalid to
flow the control onward when the condition isn't met, not only in builds
other than NDEBUG, yet C++ has exceptions to abort and avoid invalid
continuation too. Typically even programs compiled for systems without
catch can throw which can just abort much like a failed assert does on
those systems. Then, for performance concerns for keeping the test with
NDEBUG, the constructor is inlineable so the compiler could, in theory,
elide the test when the client code would never trigger it in a hot loop.
On the specific dual patterning
===============================
Do you mean it to be dual pattern either:
a) pointer to instance of any type with the required interface which
re-implements the necessary member functions
b) all work provided exactly when the client code has only a function
I feel there could be some improvement also by making the basic features
of disablement and forwarding available to derived classes which merely
then need to override a virtual member function to complete their
typical implementation. Which brings me to ...
On final
========
I'm a bit out of date, I suppose "final" prevents derivation, but why
prevent it? Some need to restrict all "new" instances to some special
array, perhaps? It would be a bit odd.
Perhaps you can't allow a vtable or such for this type or you want to
make sure "delete" can be used on pointers to "defer<what...>" without
causing a virtual destructor and therefore vtable for each?
--
Tristan Wibberley
The message body is Copyright (C) 2026 Tristan Wibberley except
citations and quotations noted. All Rights Reserved except that you may,
of course, cite it academically giving credit to me, distribute it
verbatim as part of a usenet system or its archives, and use it to
promote my greatness and general superiority without misrepresentation
of my opinions other than my opinion of my greatness and general
superiority which you _may_ misrepresent. You definitely MAY NOT train
any production AI system with it but you may train experimental AI that
will only be used for evaluation of the AI methods it implements.
Technical Details
Message-ID:
<11e11p1$1o6vh$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>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: Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk> Newsgroups: comp.lang.c++ Subject: Re: A better experimental::scope_exit Date: Mon, 23 Nov 2026 09:41:52 +0000 Organization: A noiseless patient Spider Lines: 64 Message-ID: <11e11p1$1o6vh$1@dont-email.me> References: <11dsk17$8ske$2@raubtier-asyl.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Date: Mon, 23 Nov 2026 09:41:54 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1842161"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18SCyeBgkG4BDrDnRZWo0zF6hSzCiUEIBMBvIavsmBHDw=="; posting-host="f3ae5d3a9839bbc9868d42f7eef6253b" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:OIKe3Oy7w/cV7LdOCkA/GTJpPOM= sha256:6ujo6tMdZVehQ/3GYCFqTc9MdgU8/NHCoW2KzRhzi0U= sha1:eHgAs4U+TTAwMNJ0sldfR5t98mY= sha256:qp72ojukGCHb1w7mtYdfmwcjWmwmV+a8qD1slmLT1VQ= Content-Language: en-GB In-Reply-To: <11dsk17$8ske$2@raubtier-asyl.eternal-september.org>