Boost logo

Boost :

Subject: Re: [boost] Proposed new RAII Library
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2012-09-14 11:43:56


On Fri, Sep 14, 2012 at 7:56 AM, Sohail Somani <sohail_at_[hidden]> wrote:
> On 14/09/2012 9:22 AM, Andrey Semashev wrote:
>>
>> On Friday 14 September 2012 09:07:07 Sohail Somani wrote:
>>>
>>> On 14/09/2012 1:36 AM, Andrey Semashev wrote:
>>>>
>>>> Actually, there's this procedure:
>>>>
>>>> http://www.boost.org/development/submissions.html
>>>>
>>>> Specifically, a formal review is required before the library can be
>>>> committed.
>>>> Also, the library author should probably read this:
>>>
>>> My view is that it's a missing feature in the existing Scope Exit
>>> library.
>>
>>
>> I don't think so. I've been using Boost.ScopeExit for quite a while and
>> don't
>> really miss the scope guard function (like the proposed RAIIFunction). If
>> it
>> is proposed it has to provide something remarkably different or benefical,
>> IMHO.
>>
>> As for the RAII wrapper, this component may well deserve its own
>> mini-library.
>
>
> A proposed library should be more than a tweak on an existing idea that fits
> just fine with an existing library. BOOST_SCOPE_EXIT is way overkill for
> simple handle closing or transaction commit operations:
>
> BOOST_SCOPE_EXIT( (&handle) )
> {
> CloseHandle(handle);
> }
>
> vs
>
> boost::scope_exit OMGINEEDANAME(CloseHandle,handle);
>
> I'd even be OK with:
>
> BOOST_SCOPE_EXIT(CloseHandle,handle);

Please consider programming:

#define UNARY_SCOPE_EXIT(unary_func, arg) \
    BOOST_SCOPE_EXIT( (&arg) ) { \
        unary_func(arg); \
    } BOOST_SCOPE_EXIT_END

And then:

UNARY_SCOPE_EXIT(CloseHandle, handle);

That way the code for this one specialized use case of Scope Exit
becomes closer to what your expressed preference is. You can of course
put this macro #definition into your own little lib
scope_exit_arity.hpp and re-use it across your different projects :)

> Too many curly braces in my code already. I need more :: and BOOST_*

HTH,
--Lorenzo


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