Boost logo

Boost :

Subject: Re: [boost] Proposed new RAII Library
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2012-09-15 13:55:46


On Sat, Sep 15, 2012 at 6:26 AM, Sohail Somani <sohail_at_[hidden]> wrote:
> On 15/09/2012 2:16 AM, Lorenzo Caminiti wrote:
>>>
>>> >Lorenzo, thanks for volunteering but the design and implementation is
>>> > far
>>> >more complex than the extract from the doc. If we want it to be
>>> > efficient,
>>> >it shouldn't use boost.function,
>>> > boost/multi_index/detail/scope_guard.hpp
>>> >should be a good staring point.
>>
>> I see. Then (speaking personally) it might make sense for it to exist
>> in a lib as its impl is not trivial due to the optimization efforts.
>> However, I probably won't have time to add this feature to Scope
>> Exit...
>
>
> Ahhhh!
>
> The needed class is already part of scope exit.

What's there as boost::scope_exit::aux::guard is similar to what shown
in the examples as scope_exit but it uses the operator= and it has a
default constructor instead of using the constructor to initialize the
functor. It is used to implement the Scope Exit macros using C++11
lambdas but only if !BOOST_NO_LAMBDA and
BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS--see the bottom of this
subsection:
http://www.boost.org/doc/libs/1_51_0/libs/scope_exit/doc/html/scope_exit/tutorial.html#scope_exit.tutorial.capturing_all_variables__c__11_only_

> Just add a dismiss function,

I wouldn't add the dismiss functionality. That is not always needed
with RAII and the Scope Exit API is more generic without it. If users
need such functionality, they can use a commit/dismiss variable
external to Scope Exit to simply implement it:

    struct scope_exit {
        scope_exit(std::function<void (void)> f) : f_(f) {}
        ~scope_exit(void) { f_(); }
    private:
        std::function<void (void)> f_;
    };

    bool commit = false;

    persons_.push_back(a_person);
    scope_exit on_exit1([&commit, this]() {
        if(!commit) persons_.pop_back();
    });

> take it out of aux/detail and I WILL BE YOUR UNCLE, forget about Bob.
>
> Forget the optimization. Boost Scope.Exit doesn't use any of these tricks
> right? It's already using a boost function.
>
> Lorenzo my man, just add it.

As I said I could but only if it's about adding something as simple as
the above scope_exit... I'm not sure if that's enough.

HTH,
--Lorenzo


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