Boost logo

Boost :

Subject: Re: [boost] Proposed new RAII Library
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2012-09-14 11:12:05


On Friday 14 September 2012 10:56:46 Sohail Somani wrote:
> On 14/09/2012 9:22 AM, Andrey Semashev wrote:
> >
> > 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);
>
> Too many curly braces in my code already. I need more :: and BOOST_*

Your last two examples fit the "RAII wrapper" I was referring to. But I don't
think this wrapper belongs to Boost.ScopeExit (or, rather, it doesn't deserve
own library). What if I want to keep that handle as a class member (and,
naturally, call CloseHandle when destructor is called)? You could argue that
the call to CloseHandle could be hardcoded in my class' destructor but that is
inconvinient an error prone. Why not:

  typedef raii< HANDLE, &CloseHandle > auto_handle;

  class my_class
  {
    auto_handle m_h;
  };

This doesn't look like a part of Boost.ScopeExit anymore.


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