|
Boost : |
Subject: Re: [boost] Proposed new RAII Library
From: Ivan Sorokin (vanyacpp_at_[hidden])
Date: 2012-09-14 16:27:08
On 12.09.2012 05:40, Andrew Sandoval wrote:
> The first of these is RAIIFunction (I'm open to other names and coding
> conventions).
This approach has one problem.
The typical usage is something like that:
FILE* f = fopen(...);
if (!f)
return;
RAIIFunction<void> close_f = [f](){ fclose(f); } // may throw!!!
The construction of std::function for RAIIFunction may throw
std::bad_alloc. In that case you will get leaked file handle.
That is why approach with scope capturing reference to a base class is
better.
> The other one I call just RAIIWrapper, and it works with static
> deleter functions taking a single argument of the type being delete.
This is somewhat similar to my library RCPP.
http://rain.ifmo.ru/~sorokin/rcpp/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk