Boost logo

Boost :

Subject: Re: [boost] Proposed new RAII Library
From: Peter Dimov (lists_at_[hidden])
Date: 2012-09-16 13:22:18

On 12-09-16 9:35 AM, Krzysztof Czainski wrote:
> So, maybe the dismiss functionality can be an external function
> (assuming a guard can be rebound to another function):
> void do_nothing() {}
> void dismiss( guard& ) { guard = do_nothing; }

guard::operator=( guard const& ), if it exists, should probably execute the
stored function before replacing it. To see why, consider:

struct X
    guard g_;
    FILE* f_;

    explicit X( FILE* f ): g_( fclose, f ), f_( f ) {}

and think what happens in X::operator=( X const& ).

dismiss() is different - it's the equivalent of auto_ptr::release (not of
auto_ptr::op= or reset).

And yes, I do see that the above example uses guard::op=( F f ), not the
copy assignment, but it wouldn't be very consistent for the two to differ in
such a fundamental way.

Boost list run by bdawes at, gregod at, cpdaniel at, john at