Structure for a block created specifically for controlling the lifetime of RAII object. #682
Closed
gregmarr
started this conversation in
Suggestions
Replies: 1 comment 1 reply
-
In Cpp2, you can use a parameterized statement (https://cpp2.godbolt.org/z/16rz7YqPr):
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is based on a recent real-life internal discussion.
Problem statement: user wants to make it more explicit why a particular scope block exists in the code.
Current methods:
Newer method that someone thought about but didn't really like:
Someone suggested that it would be nice to have something similar to Python's "with"
or if the RAII object doesn't need to be accessed, and just needs a lifetime scope:
There were a couple attempts to emulate this with lambdas and helper structs, but they weren't pretty. I'm interested to see what kinds of solutions might already exist with Cpp2, or if it's something that could be added.
Beta Was this translation helpful? Give feedback.
All reactions