[scope_exit] Doesn't included in Boost yet?

Hi, I didn't found boost::scope_exit library in Boost 1.37 althougth the library approved in May 2008. Why? Kind regards, Dmitriy

Dmitriy Maksimov <dmitriy.maksimov <at> redoxygen.com> writes:
Hi,
I didn't found boost::scope_exit library in Boost 1.37 althougth the library approved in May 2008. Why?
Hi Dmitriy, I commited code and tests on the last day for new libraries (Dec 20th) but the commit didn't appear in the repository. I didn't realise that my commit required prior approvals (I later re-read the guide and found this requirement) so it could be rejected by svn admin. I wrote to Beman few days later but got no reply. As we're getting closer to C++0x with lambdas, scope_exit becomes less attractive because one can write something like: using boost::multi_index::detail; scope_guard g = make_guard( [&a, b]() -> void { /* … */ } ); Alex

Mathias Gaunard <mathias.gaunard <at> ens-lyon.org> writes:
Except C++0x lambdas are only monomorphic for now.
Can you be more specific? In my example '[&a, b]() -> void { /* … */ }', is there is any restriction on a and b (e.g. thay can't be deduced names)? Thanks, Alex

Alexander Nasonov wrote:
Mathias Gaunard <mathias.gaunard <at> ens-lyon.org> writes:
Except C++0x lambdas are only monomorphic for now.
Can you be more specific? In my example '[&a, b]() -> void { /* … */ }', is there is any restriction on a and b (e.g. thay can't be deduced names)?
The restriction isn't on variables you can capture, but on the types of the arguments. You may not write [&](a) { return a + 42; } You have to write [&](SomeType a) { return a + 42; } Boost.Lambda or Boost.Phoenix will however allow you to write _1 + 42 which is polymorphic. I don't really know about ScopeExit, but it can surely do polymorphic just as well.

Mathias Gaunard <mathias.gaunard <at> ens-lyon.org> writes:
You may not write [&](a) { return a + 42; } You have to write [&](SomeType a) { return a + 42; }
We're talking about different things. Your examples show lambda parameters while my example has no parameters at all, only captures: [&a, b]() -> void { /* ... */ } ^^ - no parameters -- Alex

Alexander Nasonov wrote:
my example has no parameters at all, only captures:
[&a, b]() -> void { /* ... */ } ^^ - no parameters
I know, I never cared about your example. I was replying to the part that I actually quoted, and not the parts I purposely removed. I care about ScopeExit as a mechanism to define inline functions with macros, and how that is more powerful than C++0x lambdas. Indeed, it seemed to me during review that it was to be generalized as such and not just be used to define inline functions to be evaluated on scope exit.

On Tue, Jan 13, 2009 at 2:41 PM, Mathias Gaunard <mathias.gaunard@ens-lyon.org> wrote:
Alexander Nasonov wrote:
my example has no parameters at all, only captures:
[&a, b]() -> void { /* ... */ } ^^ - no parameters
I know, I never cared about your example. I was replying to the part that I actually quoted, and not the parts I purposely removed.
I care about ScopeExit as a mechanism to define inline functions with macros, and how that is more powerful than C++0x lambdas.
I still I do not see how can you define *polymorphic* inline functions with ScopeExit or a similar technique (which IIRC is basically 'just' a local class). And, lacking that quality, how is it more powerful than C++0x lambdas? -- gpd

Giovanni Piero Deretta wrote:
I still I do not see how can you define *polymorphic* inline functions with ScopeExit or a similar technique (which IIRC is basically 'just' a local class).
instead of expanding the macro to ... R operator()(T1 t1) { ... } ... you generate ... template<typename T1> R operator()(T1 t1) { ... } ...

On Tue, Jan 13, 2009 at 4:42 PM, Mathias Gaunard <mathias.gaunard@ens-lyon.org> wrote:
Giovanni Piero Deretta wrote:
I still I do not see how can you define *polymorphic* inline functions with ScopeExit or a similar technique (which IIRC is basically 'just' a local class).
instead of expanding the macro to
... R operator()(T1 t1) { ... } ...
you generate
... template<typename T1> R operator()(T1 t1) { ... } ...
That's the problem. Unfortunately you can't have a templated local class. AFAIK, Not even in C++0x. -- gpd

Alexander Nasonov wrote:
As we're getting closer to C++0x with lambdas, scope_exit becomes less attractive because one can write something like:
using boost::multi_index::detail; scope_guard g = make_guard( [&a, b]() -> void { /* … */ } );
That will be nice, however, wide adoption of C++0x is still quite distant. ScopeExit is a very good solution for C++03, I'm eagerly waiting for its inclusion.

That will be nice, however, wide adoption of C++0x is still quite distant. ScopeExit is a very good solution for C++03, I'm eagerly waiting for its inclusion.
I second that. I think we can always "0xize" the library later on, and probably that boost is going to change a little when C++0x arrives anyway so this could be part of that process. Philippe

Philippe Vaucher <philippe.vaucher <at> gmail.com> writes:
I second that. I think we can always "0xize" the library later on, and probably that boost is going to change a little when C++0x arrives anyway so this could be part of that process.
Beman gave me permission to commit the library. I'll do it tonight. Regarding "0xfication", see my other post for capture list syntax. C++0x code will be nicer: BOOST_SCOPE_EXIT(&a, &b, c) { std::cout << a << '\n' << b << '\n' << c << '\n'; } Variadic pp args and no BOOST_SCOPE_EXIT_END after the closing bracket. Thanks, Alex

On Wed, Jan 14, 2009 at 1:04 PM, Alexander Nasonov <alnsn@yandex.ru> wrote:
Philippe Vaucher <philippe.vaucher <at> gmail.com> writes:
I second that. I think we can always "0xize" the library later on, and probably that boost is going to change a little when C++0x arrives anyway so this could be part of that process.
Beman gave me permission to commit the library. I'll do it tonight.
Regarding "0xfication", see my other post for capture list syntax.
C++0x code will be nicer:
BOOST_SCOPE_EXIT(&a, &b, c) { std::cout << a << '\n' << b << '\n' << c << '\n'; }
Variadic pp args and no BOOST_SCOPE_EXIT_END after the closing bracket.
Why declare the captured variables at all? What is the benefit? In c++0x this should be possible: BOOST_SCOPE_EXIT { //code here } A ScopeExit never outlives the containing scope, so capturing by reference the whole frame should be always safe. -- gpd

Giovanni Piero Deretta <gpderetta <at> gmail.com> writes:
Why declare the captured variables at all? What is the benefit? In c++0x this should be possible:
BOOST_SCOPE_EXIT { //code here }
// Capture all local variables inside the block by reference: BOOST_SCOPE_EXIT(&) { } // Capture all local variables inside the block by value: BOOST_SCOPE_EXIT(=) { } // Capture a and b by reference, c by value, // all other local variables by reference BOOST_SCOPE_EXIT(&, &a, &b, c) { } // Capture a and b by reference, c by value, // all other local variables by value BOOST_SCOPE_EXIT(=, &a, &b, c) { } Alex
participants (6)
-
Alexander Nasonov
-
Andrey Semashev
-
Dmitriy Maksimov
-
Giovanni Piero Deretta
-
Mathias Gaunard
-
Philippe Vaucher