Thread View: comp.lang.c++
27 messages
27 total messages
Started by Bonita Montero
Sat, 21 Nov 2026 17:22
A better experimental::scope_exit
Author: Bonita Montero
Date: Sat, 21 Nov 2026 17:22
Date: Sat, 21 Nov 2026 17:22
51 lines
2439 bytes
2439 bytes
#pragma once
#include <type_traits>
#include <cassert>
#include <utility>
#include "nui.hpp"
template<typename Fn, typename Dependent = void>
struct defer final
{
static_assert( std::is_nothrow_invocable_v<Fn> );
defer( Fn fn, Dependent *pDep = (Dependent *)nullptr ) :
m_enabled( true ),
m_fn( std::move( fn ) ),
m_pDep( pDep )
{
assert(std::is_void_v<Dependent> || pDep);
}
defer( defer const & ) = delete;
void operator =( defer const & ) = delete;
~defer()
{
run();
}
void run() noexcept
{
constexpr bool DepRunnable = requires { { m_pDep->run() }; };
static_assert( DepVoid || DepRunnable );
if( !m_enabled )
return;
m_fn();
m_enabled = false;
if constexpr( DepRunnable )
m_pDep->run();
}
void disable() noexcept
{
constexpr bool DepDisable = requires { { m_pDep->disable() }; };
static_assert( DepVoid || DepDisable );
m_enabled = false;
if constexpr( DepDisable )
m_pDep->disable();
}
private:
bool m_enabled;
NO_UNIQUE_ADDRESS Fn m_fn;
struct empty { empty( void * ) {} };
static constexpr bool DepVoid = std::is_void_v<Dependent>;
using dep_t = std::conditional_t<std::is_void_v<Dependent>, empty,
Dependent *>;
NO_UNIQUE_ADDRESS dep_t m_pDep;
};
Re: A better experimental::scope_exit
Author: Bonita Montero
Date: Sun, 22 Nov 2026 17:34
Date: Sun, 22 Nov 2026 17:34
57 lines
2714 bytes
2714 bytes
Now it's perfect.
#pragma once
#include <type_traits>
#include <cassert>
#include <utility>
#include "nui.hpp"
template<typename Fn, typename Dependent = void>
struct defer;
template<typename Fn, typename Dependent>
struct defer final
{
static_assert( std::is_nothrow_invocable_v<Fn> );
defer( Fn fn, Dependent *pDep = (Dependent *)nullptr ) :
m_enabled( true ),
m_fn( std::move( fn ) ),
m_pDep( pDep )
{
assert(std::is_void_v<Dependent> || pDep);
}
defer( defer const & ) = delete;
void operator =( defer const & ) = delete;
~defer()
{
run();
}
void run() noexcept
{
if( !m_enabled )
return;
m_fn();
m_enabled = false;
if constexpr( !std::is_void_v<Dependent> )
m_pDep->run();
}
void disable() noexcept
{
m_enabled = false;
if constexpr( !std::is_void_v<Dependent> )
m_pDep->disable();
}
private:
template<typename T>
struct is_defer : std::false_type {};
template<typename Fn, typename Dependent>
struct is_defer<defer<Fn, Dependent>> : std::true_type {};
static_assert( std::is_void_v<Dependent> || is_defer<Dependent>::value );
bool m_enabled;
NO_UNIQUE_ADDRESS Fn m_fn;
struct empty { empty( void * ) {} };
static constexpr bool DepVoid = std::is_void_v<Dependent>;
using dep_t = std::conditional_t<std::is_void_v<Dependent>, empty,
Dependent *>;
NO_UNIQUE_ADDRESS dep_t m_pDep;
};
Re: A better experimental::scope_exit
Author: 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.
Re: A better experimental::scope_exit
Author: David Brown
Date: Mon, 23 Nov 2026 12:26
Date: Mon, 23 Nov 2026 12:26
87 lines
4312 bytes
4312 bytes
On 21/11/2026 18:22, Bonita Montero wrote:
> #pragma once
> #include <type_traits>
> #include <cassert>
> #include <utility>
> #include "nui.hpp"
A dependency on a non-standard header - if your code really is dependent
on "nui.hpp" - makes your code useless to anyone else.
Apart from that, what makes you think your version is "better" than the
the proposed standard version in "experimental::" ?
Or the C++ "defer" version here?
<https://gustedt.wordpress.com/2025/01/06/simple-defer-ready-to-use/>
Or any other simple RAII wrapper like :
template<typename T>
struct scope_exit {
T f;
scope_exit(T f) : f(f) { }
~scope_exit() { f(); }
};
or a template on a lambda (like in Gustedt's version) ?
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. And if you are going to require the use of C++20
for 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.
>
> template<typename Fn, typename Dependent = void>
> struct defer final
> {
> static_assert( std::is_nothrow_invocable_v<Fn> );
> defer( Fn fn, Dependent *pDep = (Dependent *)nullptr ) :
> m_enabled( true ),
> m_fn( std::move( fn ) ),
> m_pDep( pDep )
> {
> assert(std::is_void_v<Dependent> || pDep);
> }
> defer( defer const & ) = delete;
> void operator =( defer const & ) = delete;
> ~defer()
> {
> run();
> }
> void run() noexcept
> {
> constexpr bool DepRunnable = requires { { m_pDep->run() }; };
> static_assert( DepVoid || DepRunnable );
> if( !m_enabled )
> return;
> m_fn();
> m_enabled = false;
> if constexpr( DepRunnable )
> m_pDep->run();
> }
> void disable() noexcept
> {
> constexpr bool DepDisable = requires { { m_pDep->disable() }; };
> static_assert( DepVoid || DepDisable );
> m_enabled = false;
> if constexpr( DepDisable )
> m_pDep->disable();
> }
> private:
> bool m_enabled;
> NO_UNIQUE_ADDRESS Fn m_fn;
> struct empty { empty( void * ) {} };
> static constexpr bool DepVoid = std::is_void_v<Dependent>;
> using dep_t = std::conditional_t<std::is_void_v<Dependent>, empty,
> Dependent *>;
> NO_UNIQUE_ADDRESS dep_t m_pDep;
> };
Re: A better experimental::scope_exit
Author: Bonita Montero
Date: Mon, 23 Nov 2026 14:00
Date: Mon, 23 Nov 2026 14:00
33 lines
2780 bytes
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.
Re: A better experimental::scope_exit
Author: Bonita Montero
Date: Mon, 23 Nov 2026 14:07
Date: Mon, 23 Nov 2026 14:07
42 lines
3227 bytes
3227 bytes
Am 23.11.2026 um 10:41 schrieb Tristan Wibberley: > 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"? The code is correct. If the node our node depends on isn't 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. The code should result in a debug break point and usually the debugger doesn't allow any further execution. That's exactly what I want. An exception is the wrong thing here. > 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 If you have a disable() on the last node in a chain all nodes we're depending on should also be disabled. If you call a run in the same manner all nodes we depend on should be executed also. Why is that so hard to understand ? It's one screenpage of code. > 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 ... With virtual functions this woudln't be that lightweight I implemented it. > 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. An extension woudln't make sense. Also because the innards of the class are private.
Re: A better experimental::scope_exit
Author: 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.
Re: A better experimental::scope_exit
Author: Bonita Montero
Date: Mon, 23 Nov 2026 14:33
Date: Mon, 23 Nov 2026 14:33
23 lines
2201 bytes
2201 bytes
Am 23.11.2026 um 15:19 schrieb David Brown: > That is not an example - it's a vague idea of an imagined use-case. Ususally I don't cascade. But I had this usecase multiple times when applying several changes on a data structure where each operation could fail with an exception. > Try showing an example, using your scope_exit. Can't you imagine the purpose from the code - poor ! > Compare it with alternatives. ... experimental::scope_exit hasn't cascading and no explicit run(). > 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. You really have a lack of imagination. Or you don't understand the code.
Re: A better experimental::scope_exit
Author: David Brown
Date: Mon, 23 Nov 2026 15:45
Date: Mon, 23 Nov 2026 15:45
47 lines
3612 bytes
3612 bytes
On 23/11/2026 15:33, Bonita Montero wrote: > Am 23.11.2026 um 15:19 schrieb David Brown: > >> That is not an example - it's a vague idea of an imagined use-case. > > Ususally I don't cascade. But I had this usecase multiple times when > applying several changes on a data structure where each operation > could fail with an exception. > >> Try showing an example, using your scope_exit. > > Can't you imagine the purpose from the code - poor ! > >> Compare it with alternatives. ... > > experimental::scope_exit hasn't cascading and no explicit run(). > >> 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. > > You really have a lack of imagination. > Or you don't understand the code. Programming is not just a matter of churning out lines of code. Claiming things are "obvious" or that others "lack imagination" is an excuse for being unable or unwilling to explain your own thoughts. If you have trouble explaining things, then the suggestions below will help. If you are simply unwilling to do so, then why bother posting the code in the first place? It is unusable to others as it is, and contains nothing particularly innovative. If you are posting it so that we can discuss it, then that's great - so discuss it. If not, then why did you post it? Figure out what you want to achieve. Figure out how the code should be used. Specify it, describe it, document it. Show examples. Compare it to existing solutions. Show why your "defer" class with "Dependent" pointers is necessary, and better than a single "standard" scope_exit function that does more than one thing, or multiple "standard" scope_exit calls. Explain why it is so common to need theses "Dependent" variables that they should be included in a general "defer" class, rather than a specialised version used occasionally. Explain why a single "Dependent" is enough, rather than accepting multiple "Dependents". Explain what you mean by "Dependent" in the first place.
Re: A better experimental::scope_exit
Author: Bonita Montero
Date: Mon, 23 Nov 2026 15:54
Date: Mon, 23 Nov 2026 15:54
31 lines
2875 bytes
2875 bytes
Am 23.11.2026 um 16:45 schrieb David Brown: > Claiming things are "obvious" or that others "lack imagination" is > an excuse for being unable or unwilling to explain your own thoughts. It's just one screenpage of code. And the code itself is simpler than any real world application. So where's the problem ? > If you have trouble explaining things, then the suggestions below will > help. If you are simply unwilling to do so, then why bother posting > the code in the first place? It is unusable to others as it is, and > contains nothing particularly innovative. Then you still don't understand what I did. > Figure out what you want to achieve. Figure out how the code should be > used. Specify it, describe it, document it. Show examples. Compare it > to existing solutions. Show why your "defer" class with "Dependent" > pointers is necessary, and better than a single "standard" scope_exit > function that does more than one thing, or multiple "standard" > scope_exit calls. The ide is somewhat unusual, but as the code is very short it's not hard to understand. > Explain why single "Dependent" is enough, rather than accepting multiple > "Dependents". Explain what you mean by "Dependent" in the first place. I see: you didn't understand the code. The dependents could be cascaded.
Re: A better experimental::scope_exit
Author: Scott Lurndal
Date: Mon, 23 Nov 2026 16:37
Date: Mon, 23 Nov 2026 16:37
56 lines
2525 bytes
2525 bytes
Bonita Montero <Bonita.Montero@gmail.com> writes:
>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.
KISS. This is from a 1992-ish port of Unix to run as
an actor for the Chorus microkernel.
//
// Destructor: undo what fork has done upon failure.
//
tForkFailure::~tForkFailure()
{
if (ret == 0) {
return;
}
if (PActUI != NULL) {
procp->Mem.Exit(ChildCap);
}
//
// XXXKYS: the DeleteAll() needs to take
// into account that some of the LWPs
// in the list may be zombies.
//
procp->LwpList.DeleteAll();
if (rgn == B_TRUE) {
procp->Rgn.ShmExit(CrLwp, procp);
}
if (file == B_TRUE) {
procp->File.ForkUndo();
}
procp->ProcRlim->rlFree(nlwp + 1);
procp->ProcCred->CrFree(nlwp + 1);
procp->UidQuota.FreeProc(B_TRUE, total_lwp, 1);
}
Aside: The KYS referenced in the comment is now a VP at Microsoft.
Re: A better experimental::scope_exit
Author: boltar
Date: Mon, 23 Nov 2026 16:46
Date: Mon, 23 Nov 2026 16:46
29 lines
2089 bytes
2089 bytes
On Mon, 23 Nov 2026 16:37:32 GMT
scott@slp53.sl.home (Scott Lurndal) gabbled:
>Bonita Montero <Bonita.Montero@gmail.com> writes:
>>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.
>
>KISS. This is from a 1992-ish port of Unix to run as
>an actor for the Chorus microkernel.
>
>//
>// Destructor: undo what fork has done upon failure.
>//
>tForkFailure::~tForkFailure()
Why is fork failure a specific class? Thats a bit wierd.
Re: A better experimental::scope_exit
Author: David Brown
Date: Mon, 23 Nov 2026 16:58
Date: Mon, 23 Nov 2026 16:58
41 lines
3317 bytes
3317 bytes
On 23/11/2026 16:54, Bonita Montero wrote: > Am 23.11.2026 um 16:45 schrieb David Brown: > >> Claiming things are "obvious" or that others "lack imagination" is >> an excuse for being unable or unwilling to explain your own thoughts. > > It's just one screenpage of code. And the code itself is simpler than > any real world application. So where's the problem ? > >> If you have trouble explaining things, then the suggestions below will >> help. If you are simply unwilling to do so, then why bother posting >> the code in the first place? It is unusable to others as it is, and >> contains nothing particularly innovative. > > Then you still don't understand what I did. > > >> Figure out what you want to achieve. Figure out how the code should >> be used. Specify it, describe it, document it. Show examples. >> Compare it to existing solutions. Show why your "defer" class with >> "Dependent" pointers is necessary, and better than a single "standard" >> scope_exit function that does more than one thing, or multiple >> "standard" scope_exit calls. > > The ide is somewhat unusual, but as the code is very short it's > not hard to understand. > >> Explain why single "Dependent" is enough, rather than accepting >> multiple "Dependents". Explain what you mean by "Dependent" in the >> first place. > I see: you didn't understand the code. > The dependents could be cascaded. > The code is not the problem. The /purpose/ of the code is the problem. Since you apparently cannot or will not give any explanation or usage of the code, there is nothing more to be said about it. In the future, I'd recommend you send such pointless code straight to /dev/null and don't bother posting anything you are unwilling to talk about.
Re: A better experimental::scope_exit
Author: Bonita Montero
Date: Mon, 23 Nov 2026 17:02
Date: Mon, 23 Nov 2026 17:02
15 lines
2106 bytes
2106 bytes
Am 23.11.2026 um 17:58 schrieb David Brown: > Since you apparently cannot or will not give any explanation or > usage of the code, there is nothing more to be said about it. ... I gave an explanation and I said that I use the cascading torevert a number of changes on a data structure if the changes aren't complete. > In the future, I'd recommend you send such pointless code straight > to /dev/null and don't bother posting anything you are unwilling > to talk about. You're a sick nerd.
Re: A better experimental::scope_exit
Author: Scott Lurndal
Date: Mon, 23 Nov 2026 17:35
Date: Mon, 23 Nov 2026 17:35
135 lines
5738 bytes
5738 bytes
boltar@caprica.universe writes:
>On Mon, 23 Nov 2026 16:37:32 GMT
>scott@slp53.sl.home (Scott Lurndal) gabbled:
>>Bonita Montero <Bonita.Montero@gmail.com> writes:
>>>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.
>>
>>KISS. This is from a 1992-ish port of Unix to run as
>>an actor for the Chorus microkernel.
>>
>>//
>>// Destructor: undo what fork has done upon failure.
>>//
>>tForkFailure::~tForkFailure()
>
>Why is fork failure a specific class? Thats a bit wierd.
>
Because it is used as a cleanup task to simplify the
Fork functionality, to wit:
/
// int tProc::Fork(KnCap* PActUI, int Caller, tLwp *CrLwp,
// int IsVFork, boolean_t ForkAll)
// Perform all the fork time operations for the invoking object.
//
// Calling/Exit State:
// On entry, the LWPs in the parent process other than the forking LWP
// are at a barrier. Further, the process reader/writer lock of the
// parent process has been acquired (in the read mode) to keep /proc
// at bay. The invoking object is fully initialized from the parent
// process. All the embedded synchronization objects have been initialized.
//
// Remarks:
// The only asynchronous activity in the parent is the result of
// message handlers executing in the parent.
int
tProc::Fork(KnCap* PActUI, int Caller, tLwp *CrLwp, int IsVFork, boolean_t ForkAll)
{
int Error = 0;
int nlwp; // total number of active lwps in the child
int total_lwp; // total number of lwps in the child (active + zombies)
ASSERT((Caller == FORK_SYSCALL) || (Caller == FORK_BOOTPROC));
KnCap *ChildCap = Actor.GetCap();
// Hand crafted processes do not have a ParentP.
tProc *ParentP = CrLwp->MyProc();
// Initialise the global Ops event that is used for global Ops
// synchronisation
EVENT_INIT(&GlobalEvt);
//
// Only Single threaded processes can vfork().
// Currently, we don't support vfork.
if (IsVFork && (!(ParentP->LwpList.SingleThreaded()))) {
return EINVAL;
}
if (ForkAll) {
nlwp = ParentP->LwpList.GetCountLwp();
total_lwp = ParentP->LwpList.GetTotalLwp();
} else {
nlwp = 1;
total_lwp = 1;
}
//
// Check to see if we will be exceeding the quota.
// XXXKYS: Check the interface for picking up quota tokens.
// Would prefer an interface that accepted the number of
// tokens needed - proc + lwps.
// NOTE: The number of LWP tokens picked up will be equal to the
// total number of LWPs in the child (including zombie LWPs).
if (UidQuota.Fork(ProcCred->GetUid(), ProcCred->GetEuid(), total_lwp)) {
return EAGAIN;
}
>>> After this point, any resources allocated to the newly created
>>> process must be deallocated if the fork() fails (e.g. due to
>>> insufficient resources,
tForkFailure ff(this, CrLwp, ChildCap, nlwp, total_lwp);
//
// Perform fork time operations on the credentials.
// Basically, apply the necessary holds.
// NOTE: The UID state we have inherited corresponds to the
// credential state we have inherited (at the process level).
// We will synch up all the LWPs in the child to the process
// level cred state.
ProcCred->CrHold(nlwp + 1);
//
// Perform the fork time operations on the resource limits.
// Refer to the note under the credential operation above.
ProcRlim->rlHold(nlwp + 1);
...
//
// Write an accounting record
//
ParentP->Acct.Fork(); // Count another child
if (SystemAccounting.isEnabled( ACCT_FORK )) {
EventFork rec( ParentP, this );
rec.Write();
}
return ff.ret = 0; // OK
} // tProc::Fork
Re: A better experimental::scope_exit
Author: Tristan Wibberley
Date: Mon, 23 Nov 2026 22:49
Date: Mon, 23 Nov 2026 22:49
21 lines
2258 bytes
2258 bytes
On 21/11/2026 17:22, Bonita Montero wrote: > if( !m_enabled ) > return; > m_fn(); This might re-enter which is probably counter-intuitive for the role of a scope guard. Setting m_enabled to false before evaluating "m_fn()" might be better. -- 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.
Re: A better experimental::scope_exit
Author: Tristan Wibberley
Date: Tue, 24 Nov 2026 00:12
Date: Tue, 24 Nov 2026 00:12
38 lines
3377 bytes
3377 bytes
On 21/11/2026 17:22, Bonita Montero wrote: > static_assert( std::is_nothrow_invocable_v<Fn> ); The facility is here eliciting the feeling that, by using it, one may disregard the possibility that exceptions pass out of it's members and destructor or that exceptions passing out of the callbacks I provide to it are unable to affect its behaviours that I intuitively expect. However, only Fn is tested for being nothrow invocable. There are also ::run and ::disable of the dependency node to consider. There is much to talk about on interface design so this would be longwinded and annoying if I did. I wonder if it's better to work with client callbacks that throw exceptions so the surprises of the limited compose-ability are removed. I suppose it depends on the scale of the development that the class is being used in. Does C++ still allow noexcept(false) destructors and does an exception at the end of a destructor allow the members to be destroyed? My memory failed in the last few years and I can't remember - I think it does but I can't bring a justification for the belief to mind, I think I previously relied on advice from journalists that it does. Then there would be some thought needed for how exceptions from m_fn() and m_pDep::run() interact, c++ has nested exceptions now doesn't it so a list can be collected up can't it, which would be sufficient for this particular facility being that it's list-like. -- 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.
Re: A better experimental::scope_exit
Author: Bonita Montero
Date: Tue, 24 Nov 2026 06:12
Date: Tue, 24 Nov 2026 06:12
25 lines
2683 bytes
2683 bytes
Am 24.11.2026 um 01:12 schrieb Tristan Wibberley: > The facility is here eliciting the feeling that, by using it, one may > disregard the possibility that exceptions pass out of it's members and > destructor or that exceptions passing out of the callbacks I provide to > it are unable to affect its behaviours that I intuitively expect. > However, only Fn is tested for being nothrow invocable. There are also > ::run and ::disable of the dependency node to consider. My template trickery checks if the dependent node is a defer<>; so it's also checked if it's fn is also noexcept. > There is much to talk about on interface design so this would be > longwinded and annoying if I did. I wonder if it's better to work with > client callbacks that throw exceptions so the surprises of the limited > compose-ability are removed. I suppose it depends on the scale of the > development that the class is being used in. I thought about that for a while and I came to the conclusion that this scope guard isn't different from a normal destructor, which is noexcept by default; so I did it the same way to enforce Fn to be noexcept. > Does C++ still allow noexcept(false) destructors and does an exception > at the end of a destructor allow the members to be destroyed? ... Yes, you can do that; but I guess that's very uncommon.
Re: A better experimental::scope_exit
Author: Tristan Wibberley
Date: Tue, 24 Nov 2026 12:42
Date: Tue, 24 Nov 2026 12:42
121 lines
7561 bytes
7561 bytes
On 24/11/2026 06:12, Bonita Montero wrote:
> Am 24.11.2026 um 01:12 schrieb Tristan Wibberley:
>
>> The facility is here eliciting the feeling that, by using it, one may
>> disregard the possibility that exceptions pass out of it's members and
>> destructor or that exceptions passing out of the callbacks I provide to
>> it are unable to affect its behaviours that I intuitively expect.
>> However, only Fn is tested for being nothrow invocable. There are also
>> ::run and ::disable of the dependency node to consider.
>
> My template trickery checks if the dependent node is a
> defer<>; so it's also checked if it's fn is also noexcept.
Oh! I didn't notice that.
>> There is much to talk about on interface design so this would be
>> longwinded and annoying if I did. I wonder if it's better to work with
>> client callbacks that throw exceptions so the surprises of the limited
>> compose-ability are removed. I suppose it depends on the scale of the
>> development that the class is being used in.
>
> I thought about that for a while and I came to the conclusion that this
> scope guard isn't different from a normal destructor, which is noexcept
> by default; so I did it the same way to enforce Fn to be noexcept.
>
>> Does C++ still allow noexcept(false) destructors and does an exception
>> at the end of a destructor allow the members to be destroyed? ...
> Yes, you can do that; but I guess that's very uncommon.
Of course it wasn't so until C++14 when the preset mode was changed from
noexcept(false) to noexcept(true) (was it C++14?), and before C++11
there wasn't even a way to change it /from/ noexcept(false). So I think
it's really common. A unix workstation multi-process application
exhibits the most ordinary behaviours around success, failure, and
cleanup when relying on that feature (which probably explains why it was
the only easy way to do things in C++ until C++11 and was the default
until C++14.
There are also core aspects of meaning about trying to rollback/reset
and throwing if you can't rollback/reset and then aborting if you can't
reset something. Here's the original concept at least from C++98 to
C++11 (default) and C++14 (nondefault but available).
You can:
a) during primary success:
try to release resource (scope guarding) and:
1) succeed, or
2) fail with exception which unwinds (invariants maintained)
(standard scope guarding - throws from destructor)
b) during primary failure (unwinding with exception in flight):
try to release resource (scope guarding) and:
1) succeed, unwinding of the primary failure continues, or
2) secondary failure with exception which aborts because an
primary exception is already in flight
(invariants not maintained)
Those are how it was set up to work until C++11, and is obviously
correct for the limited case where one wants to abort in (b.2) which is
typical in multiprocess unix applications because invariants are not
maintained - so continuation is necessarily invalid. When one does not
make a problem with secondary exceptions having the same type or
ancestor type as primary exceptions in (a.2) - the dangers in this area
might have been a motivation for adding noexcept(true) in C++11 and
defaulting to noexcept(true) in C++14. For most ordinary scope guard
classes one does not make such a problem.
C++11 added the ability to change (b.2) so that an exception could be
nested if a destructor threw when it was being run during unwinding
instead of aborting. Then you handle the failure-to-handle-a-failure -
invariants /are/ maintained in general by conditions, but the immediate
surrounding sequence is for a tighter unconditional invariant so you
unwind that bit only and catch with the looser invariants of a degraded
mode. I haven't made good use of that but I think it's done wrong and
ought to have been done via insertion of exception translation functions
into the handler-search phase because relying on the use of try and
catch inside scope guards to translate exceptions makes a lot of new
problems vs. callbacks called at the point of the original "throw".
We now have nested exceptions so we can structure code as the above with
the below (a,b,c.i) and add in (c.ii) when (c.i) is invalid in some
special places like O/S executives where scope guards maintain
invariants over shared factors. However, I don't know how it goes when
you go and compose larger programs using the same pattern arbitrarily
deeply because I haven't used the feature.
a) assumed events:
- flow-through
b) assumed events during reset from detection of unassumed event:
- destroy objects during unwinding
c) assumed events during reset from detection of unassumed event
during reset from detection of unassumed event:
- either:
i) throw during unwinding destruction and therefrom terminate
instead of unwinding further, or
ii) throw during unwinding destruction storing the original
exception as nested exception
(a) - everyone knows and uses it
(b) - very popular (scope guards rely on it)
(c.i) - some people spend a lot of effort avoiding it and making
programs understandable only in tunnel focus
In fact, it is merely (b) with the ability to add on "and if
handling further errors gracefully is too hard, just abort
like everyone else does"
(c.ii) - I never got round to looking close enough at it.
--
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.
Re: A better experimental::scope_exit
Author: Bonita Montero
Date: Tue, 24 Nov 2026 14:01
Date: Tue, 24 Nov 2026 14:01
25 lines
2467 bytes
2467 bytes
Am 24.11.2026 um 13:42 schrieb Tristan Wibberley: > Of course it wasn't so until C++14 when the preset mode was changed from > noexcept(false) to noexcept(true) (was it C++14?), and before C++11 > there wasn't even a way to change it /from/ noexcept(false). It wasn't handled differently with any C++-version, meaning that destructors that throw exceptions are nearly no existing. > So I think it's really common. It's dangerous: If an exception occurs while unwinding the stack of a function the unwinding continues and when it is finished the exception is propagated upwards. But if you have a second exception while this unwinding happens the application is terminated. > A unix workstation multi-process application exhibits the most ordinary > behaviours around success, failure, and cleanup when relying on that > feature (which probably explains why it was the only easy way to do > things in C++ until C++11 and was the default until C++14. Show me some libs that have a noexcept( false ) destructor. Rest unread.
Re: A better experimental::scope_exit
Author: Ross Finlayson
Date: Tue, 24 Nov 2026 16:59
Date: Tue, 24 Nov 2026 16:59
164 lines
9706 bytes
9706 bytes
On 11/24/2026 04:42 AM, Tristan Wibberley wrote: > On 24/11/2026 06:12, Bonita Montero wrote: >> Am 24.11.2026 um 01:12 schrieb Tristan Wibberley: >> >>> The facility is here eliciting the feeling that, by using it, one may >>> disregard the possibility that exceptions pass out of it's members and >>> destructor or that exceptions passing out of the callbacks I provide to >>> it are unable to affect its behaviours that I intuitively expect. >>> However, only Fn is tested for being nothrow invocable. There are also >>> ::run and ::disable of the dependency node to consider. >> >> My template trickery checks if the dependent node is a >> defer<>; so it's also checked if it's fn is also noexcept. > > Oh! I didn't notice that. > > >>> There is much to talk about on interface design so this would be >>> longwinded and annoying if I did. I wonder if it's better to work with >>> client callbacks that throw exceptions so the surprises of the limited >>> compose-ability are removed. I suppose it depends on the scale of the >>> development that the class is being used in. >> >> I thought about that for a while and I came to the conclusion that this >> scope guard isn't different from a normal destructor, which is noexcept >> by default; so I did it the same way to enforce Fn to be noexcept. >> >>> Does C++ still allow noexcept(false) destructors and does an exception >>> at the end of a destructor allow the members to be destroyed? ... >> Yes, you can do that; but I guess that's very uncommon. > > Of course it wasn't so until C++14 when the preset mode was changed from > noexcept(false) to noexcept(true) (was it C++14?), and before C++11 > there wasn't even a way to change it /from/ noexcept(false). So I think > it's really common. A unix workstation multi-process application > exhibits the most ordinary behaviours around success, failure, and > cleanup when relying on that feature (which probably explains why it was > the only easy way to do things in C++ until C++11 and was the default > until C++14. > > There are also core aspects of meaning about trying to rollback/reset > and throwing if you can't rollback/reset and then aborting if you can't > reset something. Here's the original concept at least from C++98 to > C++11 (default) and C++14 (nondefault but available). > > You can: > a) during primary success: > try to release resource (scope guarding) and: > 1) succeed, or > 2) fail with exception which unwinds (invariants maintained) > (standard scope guarding - throws from destructor) > b) during primary failure (unwinding with exception in flight): > try to release resource (scope guarding) and: > 1) succeed, unwinding of the primary failure continues, or > 2) secondary failure with exception which aborts because an > primary exception is already in flight > (invariants not maintained) > > Those are how it was set up to work until C++11, and is obviously > correct for the limited case where one wants to abort in (b.2) which is > typical in multiprocess unix applications because invariants are not > maintained - so continuation is necessarily invalid. When one does not > make a problem with secondary exceptions having the same type or > ancestor type as primary exceptions in (a.2) - the dangers in this area > might have been a motivation for adding noexcept(true) in C++11 and > defaulting to noexcept(true) in C++14. For most ordinary scope guard > classes one does not make such a problem. > > C++11 added the ability to change (b.2) so that an exception could be > nested if a destructor threw when it was being run during unwinding > instead of aborting. Then you handle the failure-to-handle-a-failure - > invariants /are/ maintained in general by conditions, but the immediate > surrounding sequence is for a tighter unconditional invariant so you > unwind that bit only and catch with the looser invariants of a degraded > mode. I haven't made good use of that but I think it's done wrong and > ought to have been done via insertion of exception translation functions > into the handler-search phase because relying on the use of try and > catch inside scope guards to translate exceptions makes a lot of new > problems vs. callbacks called at the point of the original "throw". > > We now have nested exceptions so we can structure code as the above with > the below (a,b,c.i) and add in (c.ii) when (c.i) is invalid in some > special places like O/S executives where scope guards maintain > invariants over shared factors. However, I don't know how it goes when > you go and compose larger programs using the same pattern arbitrarily > deeply because I haven't used the feature. > > > a) assumed events: > - flow-through > b) assumed events during reset from detection of unassumed event: > - destroy objects during unwinding > c) assumed events during reset from detection of unassumed event > during reset from detection of unassumed event: > - either: > i) throw during unwinding destruction and therefrom terminate > instead of unwinding further, or > ii) throw during unwinding destruction storing the original > exception as nested exception > > (a) - everyone knows and uses it > (b) - very popular (scope guards rely on it) > (c.i) - some people spend a lot of effort avoiding it and making > programs understandable only in tunnel focus > In fact, it is merely (b) with the ability to add on "and if > handling further errors gracefully is too hard, just abort > like everyone else does" > (c.ii) - I never got round to looking close enough at it. > > Thanks for writing, an account of noexcept in the signature vis-a-vis nodiscard as attribute about the signature and the exception-signature, has it so that in scope-managed like block-scoped and function-scoped resource management, that exceptions are a true way in the language to give the guaranteed behavior of propagation of errors from deeper than the shallow in the usual account of a function-stack. That the industry has leaned away from exceptions since untrusted or 3'rd party code, or, bugs, otherwise would result trashing the stack, or "goto isn't good or bad, it just is", then considered to patch that back together with nodiscard prodding discipline, doesn't take it away from the language that exception-handling the stack-unwinding is already well-defined. The account of exception-translation, for example about asynchronous code which is basically covariant and about "generic" or "in-specific" or "wrapped" exceptions vis-a-vis that's just the error code and accounts of, for example, "structured errors", and since "structured exception handling", in the system and the language, has the usual account that code that swallows exceptions that aren't specifically modeled after error-modeling and exception-modeling as well-defined, is undefined behavior. Java and C++ have a lot of sympatico, basically since Java's inception and "hide all the pointers, everything's a pointer, we'll refcount the pointers", then for class theory and type theory, for example about C++'s "multiple inheritance" account vis-a-vis Java's "single inheritance" account then with Java's interfaces cum C++'s concepts, of course these things have been observed by anybody familiar with the development and maturations of these languages on their systems their eco-systems. Accounts of ownership and responsibility basically make for distinctions in types that any "move" is a "copy", that it's sort of a helper and dodgy what lives up-the-stack vis-a-vis what lives down-the-stack, which shows itself in the _holes_ of "ref ref" or "&&" where pointers have multiple purposes and should basically have own types, about "quantifier disambiguation" then "pointer disambiguation" which is these days that "universal" or, what was that, "forwarding references" or "ref ref", is a bit the bitter pill the syntactic sugar.
Re: A better experimental::scope_exit
Author: Tristan Wibberley
Date: Tue, 24 Nov 2026 19:04
Date: Tue, 24 Nov 2026 19:04
53 lines
4086 bytes
4086 bytes
On 24/11/2026 14:01, Bonita Montero wrote: > Am 24.11.2026 um 13:42 schrieb Tristan Wibberley: > >> Of course it wasn't so until C++14 when the preset mode was changed from >> noexcept(false) to noexcept(true) (was it C++14?), and before C++11 >> there wasn't even a way to change it /from/ noexcept(false). > > It wasn't handled differently with any C++-version, meaning > that destructors that throw exceptions are nearly no existing. > >> So I think it's really common. > > It's dangerous: If an exception occurs while unwinding the stack of a > function the unwinding continues and when it is finished the exception > is propagated upwards. But if you have a second exception while this > unwinding happens the application is terminated. That's what I think is the goal in many applications. That's what noexcept(false) is for. noexcept(true) is for when you want the termination every time an exception would leak from a destructor with runtime checks in case you made a booboo. When the invariants are not maintained it's dangerous to continue, the future should be broadly as if power were lost by the host or a process kill occurs (memory unit mapped into process memory is lost, etc). If you could continue safely then you can re-establish the invariant within the destructor by all sorts of means. You can throw and handle exceptions within the destructor without terminating, it is only leaking of the secondary exception out of the destructor that causes termination. The rest of the system should gracefully continue thereby making it safe (eg, failover, rapid restart, etc). Safety involves not running a program segment when its invariants do not hold. That much is fundamental. If you can run it then its invariants perhaps are more conditional after all (perhaps the system has processes and failover, stochastic redundancy and quora, etc) and maybe then you don't need any cleanup for a code segment (no problem no scope guard). -- 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.
Re: A better experimental::scope_exit
Author: Tristan Wibberley
Date: Tue, 24 Nov 2026 19:20
Date: Tue, 24 Nov 2026 19:20
23 lines
2680 bytes
2680 bytes
On 24/11/2026 19:04, Tristan Wibberley wrote: > You can throw and handle > exceptions within the destructor without terminating, it is only leaking > of the secondary exception out of the destructor that causes termination. Hang on, my memory is kicking-in some nuance and that the above is not outright true. Before C++11 there were more restrictions and the safe abort had to happen in more situations. C++11 added some features that made some things easier to do without aborting as much. I will have to refresh my memory to be able to give my perspective further. -- 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.
Re: A better experimental::scope_exit
Author: Ross Finlayson
Date: Tue, 24 Nov 2026 19:22
Date: Tue, 24 Nov 2026 19:22
85 lines
5219 bytes
5219 bytes
On 11/24/2026 11:04 AM, Tristan Wibberley wrote: > On 24/11/2026 14:01, Bonita Montero wrote: >> Am 24.11.2026 um 13:42 schrieb Tristan Wibberley: >> >>> Of course it wasn't so until C++14 when the preset mode was changed from >>> noexcept(false) to noexcept(true) (was it C++14?), and before C++11 >>> there wasn't even a way to change it /from/ noexcept(false). >> >> It wasn't handled differently with any C++-version, meaning >> that destructors that throw exceptions are nearly no existing. >> >>> So I think it's really common. >> >> It's dangerous: If an exception occurs while unwinding the stack of a >> function the unwinding continues and when it is finished the exception >> is propagated upwards. But if you have a second exception while this >> unwinding happens the application is terminated. > > That's what I think is the goal in many applications. That's what > noexcept(false) is for. noexcept(true) is for when you want the > termination every time an exception would leak from a destructor with > runtime checks in case you made a booboo. > > When the invariants are not maintained it's dangerous to continue, the > future should be broadly as if power were lost by the host or a process > kill occurs (memory unit mapped into process memory is lost, etc). > > If you could continue safely then you can re-establish the invariant > within the destructor by all sorts of means. You can throw and handle > exceptions within the destructor without terminating, it is only leaking > of the secondary exception out of the destructor that causes termination. > > The rest of the system should gracefully continue thereby making it safe > (eg, failover, rapid restart, etc). > > Safety involves not running a program segment when its invariants do not > hold. That much is fundamental. If you can run it then its invariants > perhaps are more conditional after all (perhaps the system has processes > and failover, stochastic redundancy and quora, etc) and maybe then you > don't need any cleanup for a code segment (no problem no scope guard). > > Seems you need model your resource-management that has clean-up side-effects as first-class or its own synchronization, since destructors should have no side effects (that can throw) so that their clean-up of otherwise the stack with invoking all their destructors with all their none side-effects, maintains well-defined behavior, that it seems that anonymous-routine of lambda-off-the-destructor introduces its own execution context anyways and isn't consistent with other more basic accounts of "defined behavior", i.e. it's not. One might imagine that as the language has grown that there are other conflicting accounts of "defined behavior". The very-point of error-modeling and exception-modeling is deemed necessary to "maintain invariants". "The estimated lifetime of an instance of [httpd] here before it dies randomly is 23 minutes. When it dies its last request is sent to a new one." This is longer than a usual account of "lull in conversation", which was widely estimated since forty or more years ago, as 17 minutes, though some aver 7 minutes. "Why not save it?" "Tragedy of the commons." "How about that queue over there?" "Oh, that can't go down at all." I always write const/volatile qualifiers _after_ where it's associated, instead of before, and always make the pointer or reference part of the _type_ not the _value_, since it's not like "int x = 0, *px = &x", that those are _operations_ not _qualifiers_, about then mostly assignment or "=", the "operator".
Re: A better experimental::scope_exit
Author: Tristan Wibberley
Date: Tue, 24 Nov 2026 19:24
Date: Tue, 24 Nov 2026 19:24
26 lines
2639 bytes
2639 bytes
On 24/11/2026 16:59, Ross Finlayson wrote: > has the usual > account that code that swallows exceptions that aren't specifically > modeled after error-modeling and exception-modeling as well-defined, > is undefined behavior. And so much for catch (...). If I can, I prefer to fork a child process and let the exception be handle by process abort of uncaught exceptions, the wider loop absorbs it with invariants intact (the missing process makes its own invariants go away - at the system level they're conditional on their own process existing). -- 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.
Re: A better experimental::scope_exit
Author: Tristan Wibberley
Date: Tue, 24 Nov 2026 20:18
Date: Tue, 24 Nov 2026 20:18
26 lines
2806 bytes
2806 bytes
On 24/11/2026 19:22, Ross Finlayson wrote: > destructors should have no side effects (that can throw) That's merely a deduction from contensive ontology which, as you know, is typically a matter of fantasy: 'I call them "destructor" therefore they should not throw'. But their extensional properties are of things that can throw: "Throwing in them can mean the right thing therefore they may throw". In fact they're scope-hooks at the same time so which of the succeeding program addresses (Dijkstra) should run after they run and in which conditions is the important question: "all of them all of the time" is not correct. -- 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.
Re: A better experimental::scope_exit
Author: Ross Finlayson
Date: Tue, 24 Nov 2026 20:48
Date: Tue, 24 Nov 2026 20:48
48 lines
3704 bytes
3704 bytes
On 11/24/2026 12:18 PM, Tristan Wibberley wrote: > On 24/11/2026 19:22, Ross Finlayson wrote: >> destructors should have no side effects (that can throw) > > That's merely a deduction from contensive ontology which, as you know, > is typically a matter of fantasy: 'I call them "destructor" therefore > they should not throw'. But their extensional properties are of things > that can throw: "Throwing in them can mean the right thing therefore > they may throw". > > In fact they're scope-hooks at the same time so which of the succeeding > program addresses (Dijkstra) should run after they run and in which > conditions is the important question: "all of them all of the time" is > not correct. > That's agreeable as to that it seems sensible, though, for whether it's "made sense", besides, "makes sense". Sometimes a "C++-minus" is going to be safer than "C++ any-which-way". Like you said about exception-translation, exception-translation is a first-class sort of account about a convention, since neither the language nor the compiler otherwise says, i.e., it's "undefined". I.e., either you make exception-translation or you don't, then also has the usual account that the destructor's function that throws mid-function exits the function and leaves with the thread-of-control, as it were, unfinished the destructor-body. Otherwise the usual account of exception throwing as "roll up all the automatics, like any other account of exiting block and function scope, until the exception is caught", is most what it says. What's defined is when "dtors run once for each ctor in reverse-order however which way the function exits, or the thread of it the function departs", according to the language what the compiler must generate as code. Of course it matters not so much what I say as what it is, then that the written account speaks for itself in a particularly sort of durable, irrepudiable statement. Thanks for writing, good luck in your endeavors.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads