Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for default construction to scope guards #11

Closed
Lastique opened this issue Dec 1, 2023 · 1 comment
Closed

Add support for default construction to scope guards #11

Lastique opened this issue Dec 1, 2023 · 1 comment

Comments

@Lastique
Copy link
Member

Lastique commented Dec 1, 2023

From Julien Blanc:

scope_exit is not default constructible. But it can be released and is movable, so a default constructed scope_exit state makes sense (this is the same as a moved-from scope_exit). I find this a rather strange design choice. What is the rationale behind this?

I think it does not hurt for scope_fail and scope_exit. We have scope_final for the simple case. I'm asking because i finally added it to the scope_exit-like we use in our code base.

@Lastique
Copy link
Member Author

Lastique commented Feb 2, 2024

After the following discussion, it looks like default-constructible scope guards would have a very narrow use case because a default-constructed action function must be callable (as it cannot be modified after scope guard construction) and therefore would only have access to the global state. This is rarely sufficient, you normally want to bind local variables and this in scope guards.

The original reviewer who requested this feature admitted that this would have limited usability, and another reviewer, Andzej Krzemienski, also noted that he supports the design without default constructors.

So for now I'm not going to implement this feature until there is a compelling use case and more demand from users.

@Lastique Lastique closed this as completed Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant