Will there be standardization of scope guard/scope exit idioms?
Asked Answered
R

2

9

Running a lambda on scope exit seems like such a basic thing, I would expect it to be standardized. Things like unique_ptr are better, when they apply, but I find there is an endless supply of "one-off" destructors are needed, especially when leveraging C-style libraries. Does anyone know if this is coming?

Ribbing answered 22/5, 2015 at 20:20 Comment(5)
In which cases are you using lambdas on scope exit?Questionless
Waiting for thread pool work items to complete before closing the thread pool is a good example (even when an exception is thrown you still have to wait or it will crash the workers). It's always possible to create a full C++ wrapper for each thing you do, but its so much extra code in the cases where you use it one time.Ribbing
Write a proposal? I happen to like Stefanus Du Toit's implementation (though I have no idea why he called it Auto)Detritus
@Barry: That is actually Arthur O'Dwyer's implementation - see goo.gl/0t8bXRBoyett
@Boyett Oops. Reading comprehension fail on my part. Though comment remains about Auto :)Detritus
M
10

n4189 is a proposal to add make_scope_exit wrappers, and other similar resource handlers, to the language. It is based off of the relatively famous scope_guard talk.

The most recent "current paper status" from LWG is in 2013, prior to the above date.

The contents of C++1z (hopefully C++17) are yet to be determined.

C++1z status for clang does not mention it. C++1z TS for clang does not mention it.

The paper itself contains an example implementation. I do not know what licensing terms it is under.

Mandimandible answered 22/5, 2015 at 20:47 Comment(1)
It seems to have passed LEWG, but looks like it will need better wording before it can be adopted. N4189's wording is pretty bad.Voidance
S
10

It would appear that the current version of the scope exit paper, P0052, will be going into the Library Fundamentals v3, for likely adoption in the Post-C++17 standard.

In short, not gonna happen for C++17. Sorry.

Selector answered 9/7, 2016 at 18:57 Comment(3)
Final comment that there tells about a proposal to move it to IS. Can't say whether it's gonna happen.Uncivil
@pepper_chico What is IS?Overmodest
@Jens: The International Standard. It didn't make it, btw.Selector

© 2022 - 2024 — McMap. All rights reserved.