I would like to suggest the <scope> library.
I don’t see it approved into C++26.
Maybe an implementation can help.
This is in: (p2631) - Publish TS Library Fundamentals 3 Now!
(p0052) - Generic Scope Guard and RAII Wrapper for the Standard Library
(Peter Sommerlad and Andrew L. Sandoval with contributions by Eric Niebler and Daniel Krügler)
Also: p1411- Please reconsider <scope> for C++20 (Peter Sommerlad)
Works in progress:
Peter Sommerlad’s implementation:
Great suggestion - I’d absolutely be willing to help on this given that I was planning to propose this for c++29 myself! I know Peter so we can see what his thoughts are – my guess is he might be too busy to help much. And maybe not happy as P1411 just kind of died.
There’s also new developments since the TS was published. There’s a newish boost library with mostly the same capabilities, but I believe with some divergent design decisions. We should study that and see if it deserves consideration for the proposal.
final_action is here in GSL: (Core Guidelines Support Library)
It is like scope_exit.
The GSL is missing release - which is a feature requested in the GSL issues. github: microsoft/GSL/issues/231)
Also in Core guidelines there was a discussion: (github: socpp/CppCoreGuidelines/issues/688)
In both is a helper function
In the GSL it is: finally() - convenience function to generate a final_action
In Peters library it is: make_guard.
As I see the boost version, it is more advanced, with the capability to delay activation. Or to cancel the activated guard (“release” in Peters).
My personal opinion is that there should be: on_scope_exit.
So i could write:
auto something_guard = on_scope_exit([&]{....});
Like Peter I am not happy, that it is taking so long to get such a simple library.
Yes, well for good or for ill there’s rarely anything simple at the level of standardization – every wild corner case needs discussion and attention. Also, in this case I think the proposal got caught in a time when nothing more could realistically be added to c++20 and so it got moved to a TS. Note that gcc and clang have implemented the TS – here’s a godbolt of the cppreference example:
Still I think that TS’s are rarely used in organizations unfortunately.
The evolution groups each have a general policy that the other group should use TSs, but they aren’t good for this group.
LEWG would be happy to see more EWG TS and would kd use them to vet libraries, but has seen little value in library TS. EWG, the opposite.
Beman would be a good place for something that might otherwise end up in a TS. It would at least have one implementation and would cost a lot less committee time.
Yes, I think there won’t be more additions to fundamentals TS or a new revision for that matter. Also, I think that for looking at the combination of language/library it would be ideal if Beman could support compiler branches so one could realistically look at the interactions of things.
As a side note, I’ve been debating floating the idea of a beman examples26 type repo – that just holds examples of code that track across libraries and language if the above is possible. Some Tony tables – other user resources. Both you and I have had such repos in the past, but it could become a hugely valuable resource with more contributions.
Thanks River. I can get us a paper number although I don’t think that would be a per-requisite to making a repo and getting the CI ready to hum.
In fact an initial development approach for the library might be to just pull in the TS stuff to beman namespace for clang/gcc since they’ve apparently implemented – this would allow for the development of a test suite first. To me, the most important thing is a large set of example/test code to motivate the library. Note that we will need to look at the design space afresh given newer language features and the addition to Boost.
I guess the question for @Robert-Andrzejuk is how much time he has to contribute to coding and other aspects (writing the paper) etc. But yes, I’d like to get this rolling as the 29 cycle will be starting soon.
I’d suggest we just create the skeleton for the moment and not pull in that code. At the moment it’s unclear if we want to start from that or redo from first principles.
It’s difficult to specify a concrete amount of time which I can dedicate to this project without knowing the requirements. (day job and parenting chores)
But I am willing to do some work for this.
Writing a paper … this would be a whole new level for me.
I am willing to scribe, and am not afraid of constructive criticism.
Good enough. I can lead the charge at the committee and even on handling the paper, but I need people to help review text, consider design options, update code, etc. I will, of course, try to recruit the original authors to assist. The paper will be P3610 Generic Scope Guard for C++29
And of course my generic warning about this is committee proposals typically take years – even though you’d think this should be a no-brainer that’s not my expectation.
To be clear, it’s not even a skeleton yet – just a repo and a readme. I was hoping river would pull the exemplar and setup the rest of the tree as he’s done a couple of these now.
For moving forward, I think as I mentioned elsewhere we should leverage the current implementations – and maintain those going forward. So we would basically have a macro like BEMAN_USE_SCOPE_TS3 that would compile things based on the native implementation. So rev 0 of the implementation would amount to including experimental and some using statements. This allows us to setup tests and examples while considering changes to the design and perhaps re-implementing some things.
@Robert-Andrzejuk - just so you know, @river has recreated the repo (currently scope2) from the examplar. So probably later today I’ll get to moving the little bit of context over to that repo and then deleting the current repo and renaming scope2 to scope.
Yes! And both Jeff and @Robert-Andrzejuk has been given admin access to the repo. So if any of you think it’s ready, feel free to just delete the original scope repo and rename the scope2 repo over.
I added the scope_example code from the first repo to scope2.
Also I did a VERY simple merge of README. @Jeff-Garland This is on a separate branch(not yet merged), so you can work on it there. (scope1-transfer)
The issue to create other examples has been recreated.