Boost logo

Boost :

From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2023-12-01 18:49:14


On 12/1/23 20:25, Andrzej Krzemienski via Boost wrote:
> Hi All,
> This is not a review yet. I am just looking at the front page of the docs,
> and I think the comparison with Boost.ScopeGuard is unfair.
>
> You are comparing C++03 Boost.ScopeGuard with C++11 Boost.Scope. Try
> comparing it with C++03 Boost.Scope.

Boost.Scope doesn't support C++03.

I'm comparing the libraries using the syntax they provide, regardless of
the C++ version, when they both provide equivalent functionality.

> Otherwise compare C++11 to C++11, and there Boost.ScopeGuard has a nicer
> syntax:
>
> int compute()
> {
> // Reset variables on return
> BOOST_SCOPE_EXIT(this_)
> {
> this_->x = 0;
> this_->y = 0;
> };
>
> return x + y;
> }

I don't see where the documentation makes BOOST_SCOPE_EXIT_END optional.
In every example I can see, BOOST_SCOPE_EXIT is accompanied by
BOOST_SCOPE_EXIT_END, C++11 or not. Am I missing something?

Perhaps, you are defining BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS and that
allows to omit BOOST_SCOPE_EXIT_END? In that case, there is a discussion
at the end of this section:

https://lastique.github.io/scope/libs/scope/doc/html/scope/scope_guards.html#scope.scope_guards.comparison_with_boost_scope_exit

that pertains to your use case, and that makes Boost.ScopeExit very much
not equivalent to Boost.Scope.

> Regarding the example with exceptions, nobody would use
> Boost.ScopeGuard like this. A robust usage is in Boost.ScopeGuard's
> docs:
>
>
> void world::add_person(person const& a_person) {
> bool commit = false;
>
> persons_.push_back(a_person); // (1) direct action
> // Following block is executed when the enclosing scope exits.
> BOOST_SCOPE_EXIT(&commit, &persons_) {
> if(!commit) persons_.pop_back(); // (2) rollback action
> };
>
> // ... // (3) other operations
>
> commit = true; // (4) disable rollback actions
>
> }
>
>
> Which is longer, but usable in coroutines. Whereas Boost.Scope's
> solution is not usable in coroutines.

First, what example are you referring to?

Second, if you mean incompatibility of exception_checker with coroutines
then that is already addressed in a note in this section:

https://lastique.github.io/scope/libs/scope/doc/html/scope/scope_guards.html#scope.scope_guards.condition_functions

If you're using coroutines then just don't use it. Where it is used in
library examples, it is implied that coroutines are not used.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk