
2012/9/16 Peter Dimov <lists@pdimov.com>:
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.
Right, I missed that. So dismiss(g) should not be implemented in terms of operator=, but it still can be an external function replacing the internal function with do_nothing. But maybe this point shows, that dismiss belongs inside class guard. Kris