|
Boost : |
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2023-12-01 17:25:50
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.
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;
}
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.
Only after these changes are applied, I think is the comparison fair.
Regards,
&rzej;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk