|
Boost : |
Subject: Re: [boost] Proposed new RAII Library
From: Sohail Somani (sohail_at_[hidden])
Date: 2012-09-14 23:55:08
On 14/09/2012 4:08 PM, Vicente J. Botet Escriba wrote:
>>
> Yes, I'm. Encapsulating the dismiss condition on the scope_guard doesn't
> scale when you have several actions that need to be executed. Compare
>
> bool dismiss = false;
For me it is not very common to have to dismiss more than one. Maybe
others can chime in. So for me, it would be beyond annoying to have to
declare the bool myself because I'd have to do it every single time. So
I'm back to writing my own class.
I don't think you lose anything by doing this:
struct scope_exit {
scope_exit(std::function<void (void)> f) : f_(f) {}
~scope_exit(void) { if(f) f_(); }
void dismiss(){ f_.swap(std::function<void(void)>()); } // OMG IF
WE DO THIS THIS MEANS WE ARE USING JAVA
private:
std::function<void (void)> f_;
};
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk