Boost logo

Boost :

Subject: Re: [boost] Proposed new RAII Library
From: Andrew Sandoval (sandoval_at_[hidden])
Date: 2012-09-14 14:53:09


Andrew Sandoval <sandoval <at> netwaysglobal.com> writes:

> > On 14/09/2012 11:12 AM, Andrey Semashev wrote:
> > > typedef raii< HANDLE, &CloseHandle > auto_handle;
> > > class my_class
> > > {
> > > auto_handle m_h;
> > > };
> > >
> >
>

I might add that I much prefer to not typedef RAII classes away like that
shown in the example above. If I'm putting it into another class, I like to be
able to see exactly how the resource is being dealt with.

For example:

class Something
{
private:
  RAIIWrapper<RAIIDeleter(CloseHandle),INVALID_HANDLE_VALUE> m_hFile;
  RAIIWrapper<RAIIDeleter(CloseHandle)> m_hEvent;
public:
  Something() : m_hFile(OpenSomethingFile()),
    m_hEvent(CreateEvent(NULL, TRUE, FALSE, NULL))
  {
  }

  bool IsFileOpen() const
  {
       return m_hFile.IsValid();
  }
  .
  .
  .
};

I could typedef those two into separate auto_handle's, one for each no-delete
value, but having it front and center like that IMO improves understanding of
what it is used for.

-Andrew Sandoval


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