Re: [Boost-users] Scope exit with no capture
It seems scope exit is abandoned.
Not abandoned but carefully looked after.
I'm happy to hear this.
Scroll down the post you're refering to to this line:
#define this(x) (this(x))
Check the code in http://lists.boost.org/Archives/boost/2009/05/151353.php Do we want to go that far?
What do you mean? Note that the limitation that's bothering me is having an empty capture list, not capturing this.
Also, there are some limitations (a) "this" must be first in a capture list and (b) there is no way you can use "this" inside a body if you use C++03 compiler.
So, rather than raising a learning curve for no clear benefit, I prefer being explicit and write:
YourClass *this_ = this; BOOST_SCOPE_EXIT((this_)... or YourClass& self = *this; BOOST_SCOPE_EXIT((self)...
I've not bumped into the this limitation yet. I want a clean way to run code at exit that needs no access to local variable and captures nothing. Since my compiler supports lambda, I've adopted the old scopeguard from loki. It would be great if scope_exit supported & and = capture for all needed variables as hinted in the documentation as a possibility, or better yet, reimplement scope_guard, which has better syntax. Bruno
Bruno Martinez wrote:
What do you mean? Note that the limitation that's bothering me is having an empty capture list, not capturing this.
Oops, sorry, these two things got mixed up in my mind. To be honest, I never thought of using void as a special case for an empty capture list. PP_SEQ I use for captures can't be empty. I tried supporting BOOST_PP_EMPTY() but it didn't work and I didn't like it. So, if Lorenzo's idea can work portably with C++03 and with lambdas, I can happily accept it. Alex
participants (2)
-
Alexander Nasonov
-
Bruno Martinez