
Hi folks, In contrast to BOOST_SCOPE_EXIT there is a much shorter and less verbose implementation that is especially good with c++11 lambda usage - http://alexander-stoyan.blogspot.com/2012/02/scope-exit-handlers.html ============================== Never lose heart! Regards, Alexander Stoyan http://alexander-stoyan.blogspot.com -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Stewart, Robert Sent: Tuesday, September 04, 2012 3:01 PM To: boost@lists.boost.org Subject: Re: [boost] very simple implementation of Andrei Alexandrescu's ScopeGuard idiom Sergey Radionov wrote:
2012/9/4 Stewart, Robert <Robert.Stewart@sig.com>:
Sergey Radionov wrote:
<https://github.com/RSATom/finally_execute/blob/master/finally_execute.h>
based on
<http://www.drdobbs.com/cpp/generic-change-the-way-you-write-excepti/1844037 58?pgno=2>
I know about <http://sourceforge.net/projects/loki-lib/> but with boost::bind this can be much simpler:
<https://github.com/RSATom/finally_execute/blob/master/README>
I've used this in many of my projects, and found it very usefull....
don't understand, why this simple solution does not contributed already to Boost by someone else... :)
I created a version, too, but the usage is much simpler.
Given the following:
FILE * const file(fopen("test", "r")); if (file) { // A }
Your usage, at A, is:
finally_execute _(make_fin_exec( boost::bind(fclose, file)));
Mine is:
scope_guard _(fclose, file);
As you can see, a little more complication in the component makes usage much simpler.
In this case, I think, much simple usage gives less clear code, since people reading code will see boost::bind and understand what it mean. With your version, he maybe should have to a look to help or header...
Objectively, your version requires knowing how to use boost::bind, which arguably is a good thing, and requires calling a function template, both of which make the statement more verbose. My version uses the same calling convention as, say, boost::thread: pass the function object and the arguments it requires. It even accepts a std::tr1::function<void()> so you can bind to your heart's content. As for the concern that one must read help or a header to understand how to use scope_guard, surely you jest. One cannot understand finally_execute or make_fin_exec() without doing likewise. You simply construct an instance of scope_guard with the function object to call, and any required arguments. What could be simpler?
There's also Boost.Scope Exit, though it's even more verbose: [snip unreferenced content] Rob Stewart [snip my signature block] IMPORTANT: The information contained in this email and/or [snip my employer's notice] Unsubscribe & other changes: [snip dev list's notice]
Please read http://www.boost.org/community/policy.html#quoting for guidance on how to quote on this list. _____ Rob Stewart robert.stewart@sig.com Software Engineer using std::disclaimer; Dev Tools & Components Susquehanna International Group, LLP http://www.sig.com ________________________________ IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost