Purpose adding a scope guard classes to the Boost library

, // Exceptions to be caught (up to 10 exception types supported) boost::shared_ptr< CHandler > // An optional parameter describes
Sometimes it is very useful to register some postponed actions regardless of some part of the program result (a function, for example). Smart pointers are obvious example of such actions (namely, freeing resources) and in fact are a special case of so called scope guards. Guards may be especially useful in heavilly-logical code with multiple (maybe folded into each other) checks or in code using exceptions. As a simple example, suppose we have a logging system that may trace function calls in our program. The easiest and obvious way to implement such functionality is to create some object in the beginning of each function to be traced. This object will add the function to the logger on its construction and remove it on destruction. Another application is resolving circular calling dependency issues which tend to come up in rather complex projects. The following example illustrates the problem: class A; // The objects of class B are managed by object of class A class B { public: void execute(A* pA, int n); }; // The object of main class A manages some other objects of class B class A { // Some internal data, which is provided to the managed objects std::set< int > m_Data; public: // The entrance method, called from somewhere outside void process(B* pB) { // Imagine we have some real processing here and m_Data is not empty pB->execute(this, *m_Data.begin()); // Here we cannot be absolutely sure if m_Data still contains the element we passed in line above } void remove(int n) { m_Data.erase(n); } }; void B::execute(A* pA, int n) { if (n > 10) pA->remove(n); } The case above is usually fixed by using some kind of state variables or flags or, in more complex cases, some stacks of postprocessing. I.e. in A::remove we don't actually erase the element but schedule some action to perform when control returns to A::process. This can easily be done by enqueued functors or scope guards. In some cases the latter are simplier to use and more laconic. I purpose to add a generalized scope guard classes to the Boost library. I have a rather simple but flexible implementation of such classes (I've attached the sources). Since I'm new here, I don't really know if they conform some source code conventions in Boost (if any), but if they don't - please, let me know. Few general words about the implementation. There are two general guard classes: leaving_scope_guard and scope_guard. The first one calls a functor (boost::function is used) with no arguments on its destruction if it is armed. The second class extends the first one by calling another functor on its construction (this is not a functionality of real necessity, but it allows to semantically group paired functions invocation, see the example above). A guard once created may be armed or disarmed later in thÕ program, but the armed status applies only to the destructing functor invoking (the constructing one is controlled via initial status of the guard which is passed in guard constructor arguments). The flexibility of implementation is in ability to change the functors invoking policy. In the simpliest case it is a direct invoking (all template parameters by default), but there is a policy with exception catching support. See the example: struct my_exception : public std::exception { /* ... */ }; void guarded_foo(int n, const char* p); // throws bad_cast, bad_alloc and my_exception // This is the class of the exception handler object struct CHandler { void on_exception(std::bad_cast& e) throw() { std::cout << "on_exception called, bad_cast caught" << std::endl; } void on_exception(std::bad_alloc& e) throw() { std::cout << "on_exception called, bad_alloc caught" << std::endl; } void on_exception(my_exception& e) throw() { std::cout << "on_exception called, my_exception caught" << std::endl; } }; void foo(int n) { leaving_scope_guard< guard::with_catcher< // Indicate that we're expecting some exceptions to be thrown by guarded_foo CHandler, // This is the class, which object is to process exceptions caught guard::exceptions< std::bad_cast, std::bad_alloc, my_exception the way the pointer to CHandler object should be stored. The default value would be CHandler*. > > guard(boost::bind(&guarded_foo, n, "called from foo"), boost::shared_ptr< CHandler >(new CHandler)); // Guard object // ... } There also are macroses defined for setting anonymous scope guards when there is no need for arming or disarming it. As for compatibility, I successfully compiled it on VC 7.1, ICC 9.0 and GCC 3.4.4 (MinGW version). I don 't think it will compile on VC 6 since explicit template function instantiation is used there which is not supported by the compiler, but I think it is possible to work around it. Besides that I don't think there should be any problems for other compilers. Any suggestions are welcome. begin 666 scope_guard.h M+RHA#0H@*B!<9FEL92 @('-C;W!E7V=U87)D+F@-"B J(%QA=71H;W(@4V5M M87-H978@06YD<F5Y#0H@*B!<9&%T92 @(#(U+C W+C(P,#4-"B J( T*("H@ M7&)R:65F("!'96YE<F%L:7IE9"!S8V]P92!G=6%R9"!D96-L87)A=&EO;@T* M("H@#0H@*B\-"@T*(VEF;F1E9B!?7U-#3U!%1U5!4D1?2%]?#0HC9&5F:6YE M(%]?4T-/4$5'54%21%](7U\-"@T*(VEN8VQU9&4@(F)O;W-T+V9U;F-T:6]N M+V9U;F-T:6]N,"YH<' B#0HC:6YC;'5D92 B8F]O<W0O;F]N8V]P>6%B;&4N M:'!P(@T*(VEN8VQU9&4@(F)O;W-T+W1Y<&5?=')A:71S+VES7V)A<V5?86YD M7V1E<FEV960N:'!P(@T*(VEN8VQU9&4@(F)O;W-T+W1Y<&5?=')A:71S+VES M7W!O:6YT97(N:'!P(@T*#0HO+R!-86-R;W-E<R!F;W(@9V5N97)A=&EN9R!R M96=U;&%R(&-O9&4-"B-D969I;F4@7U]30T]015]'54%21%]%3E5-15)!5$5? M34%#4D]?*&EM<&Q?;6%C<F\I7 T*"6EM<&Q?;6%C<F\H,2E<#0H):6UP;%]M M86-R;R@R*5P-"@EI;7!L7VUA8W)O*#,I7 T*"6EM<&Q?;6%C<F\H-"E<#0H) M:6UP;%]M86-R;R@U*5P-"@EI;7!L7VUA8W)O*#8I7 T*"6EM<&Q?;6%C<F\H M-RE<#0H):6UP;%]M86-R;R@X*5P-"@EI;7!L7VUA8W)O*#DI#0H-"B-D969I M;F4@7U]30T]015]'54%21%]%3E5-15)!5$5?34%#4D\H:6UP;%]M86-R;RE< M#0H):6UP;%]M86-R;R@P*5P-"@E?7U-#3U!%7T=505)$7T5.54U%4D%415]- M04-23U\H:6UP;%]M86-R;RD-"@T*(V1E9FEN92!?7U-#3U!%7T=505)$7TY5 M3$Q465!%4RAI=&5R*2!S=')U8W0@;G5L;'1Y<&4C(VET97(@.B!P=6)L:6,@ M;G5L;'1Y<&4@>WT[#0HC9&5F:6YE(%]?4T-/4$5?1U5!4D1?5$5-4$Q!5$5? M4$%204U3*&ET97(I("P@='EP96YA;64@17AC97!T:6]N5",C:71E<B ](&1E M=&%I;#HZ;G5L;'1Y<&4C(VET97(-"B-D969I;F4@7U]30T]015]'54%21%]4 M65!%1$5&4RAI=&5R*2!T>7!E9&5F($5X8V5P=&EO;E0C(VET97(@97AC97!T M:6]N7W1Y<&4C(VET97([#0HC9&5F:6YE(%]?4T-/4$5?1U5!4D1?0T%40TA% M4RAI=&5R*5P-"@EC871C:" H='EP96YA;64@17AC97!T:6]N<TQI<W14.CIE M>&-E<'1I;VY?='EP92,C:71E<B F(&4I('M<#0H)"71Y<&5D968@9&5T86EL M.CI'=6%R9$AE;'!E<CP@='EP96YA;64@17AC97!T:6]N<TQI<W14.CIE>&-E M<'1I;V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]30T]015]'54%21%].54Q,5%E015,-"B-U;F1E9B!?7U-#3U!%7T=5 M05)$7T5.54U%4D%415]-04-23PT*(W5N9&5F(%]?4T-/4$5?1U5!4D1?14Y5 M3452051%7TU!0U)/7PT*#0HC96YD:68@+R\@7U]30T]014=505)$7TA?7PT* ` end

"Andrey Semashev" <andysem@mail.ru> writes: Andrey, your mailer wraps long lines; you might want to put your code in an attachment next time. http://www.boost.org/more/discussion_policy.htm#longlines
struct my_exception : public std::exception { /* ... */ };
void guarded_foo(int n, const char* p); // throws bad_cast, bad_alloc and my_exception
// This is the class of the exception handler object struct CHandler { void on_exception(std::bad_cast& e) throw() { std::cout << "on_exception called, bad_cast caught" << std::endl; } void on_exception(std::bad_alloc& e) throw() { std::cout << "on_exception called, bad_alloc caught" << std::endl; } void on_exception(my_exception& e) throw() { std::cout << "on_exception called, my_exception caught" << std::endl; } };
void foo(int n) { leaving_scope_guard< guard::with_catcher< // Indicate that we're expecting some // exceptions to be thrown by guarded_foo CHandler, // This is the class, which object is to // process exceptions caught guard::exceptions< std::bad_cast, std::bad_alloc, my_exception >, // Exceptions to be caught (up to // 10 exception types supported)
This part worries me thes reasons: 0. I doubt its utility. 1. It induces a catch block and in many cases a catch block should be avoided when possible in exception-neutral code. 2. I think it may encourage abuse with the same lure that exception-specifications present to the casual user.
boost::shared_ptr< CHandler > // An optional parameter // describes the way the // pointer to CHandler // object should be stored. // The default value would // be CHandler*.
Do we really need all this parameterization? I think a generalized scopeguard is a good idea, but this smells like overkill.
> > guard(boost::bind(&guarded_foo, n, "called from foo"), boost::shared_ptr< CHandler >(new CHandler)); // Guard object
// ... }
-- Dave Abrahams Boost Consulting www.boost-consulting.com

"David Abrahams" <dave@boost-consulting.com> wrote in message news:<uy86u3osd.fsf@boost-consulting.com>...
"Andrey Semashev" <andysem@mail.ru> writes:
Andrey, your mailer wraps long lines; you might want to put your code in an attachment next time. http://www.boost.org/more/discussion_policy.htm#longlines
Sorry, I shall try to do so next time.
void foo(int n) { leaving_scope_guard< guard::with_catcher< // Indicate that we're expecting some // exceptions to be thrown by // guarded_foo CHandler, // This is the class, which object is to // process exceptions caught guard::exceptions< std::bad_cast, std::bad_alloc, my_exception >, // Exceptions to be caught (up to // 10 exception types supported)
This part worries me thes reasons:
0. I doubt its utility.
The guard::with_catcher template class is actually a calling policy. In this case the policy catches exceptions specified. Of course, we could write a wrapper function that never throws and use it with scope guard. But why write if it can be generated?
1. It induces a catch block and in many cases a catch block should be avoided when possible in exception-neutral code.
Yes, in case of this policy (with_catcher) it does. But if you are sure you don't need exception handling, you can use another policy (namely simple_invoker) which is the default one. In that case the guard set up would look as follows: leaving_scope_guard< > guard(bind(&guarded_foo, n, "called from foo")); // Guard object In this case there will be no try/catch blocks at all. In fact, I'm thinking about typedef'ing this form into something shorter (maybe "simple_guard"?).
2. I think it may encourage abuse with the same lure that exception-specifications present to the casual user.
I can't say I quite agree with you (if I got your opinion correctly). A tool is just a tool and of course it may be used incorrectly or ineffectively. Besides, I have a doubt that a user would prefer to use exception-parameterized guards against simple ones without having real intends to do so. For example, if a guarded function has an exception specification, we have no right to hope it will not throw it. So we shall have to catch it anyway.
boost::shared_ptr< CHandler > // An optional parameter // describes the way the // pointer to CHandler // object should be stored. // The default value would // be CHandler*.
Do we really need all this parameterization? I think a generalized scopeguard is a good idea, but this smells like overkill.
Do you mean this last template parameter in particular? with_catcher policy needs it because it cannot possibly know what to do with the handler object after the exception is processed. In many cases you won't need to worry about it and will be passing this as a pointer to the handler object. In such cases you can simply skip this template argument. But sometimes you might want to pass error hanlding to another object and you will have to guarantee its existance until the guard is destroyed.
> > guard( boost::bind(&guarded_foo, n, "called from foo"), boost::shared_ptr< CHandler >( new CHandler) ); // Guard object // ... }
PS: I attach the source code once more. I hope this time it will be correct. If it doesn't work this time I can mail it if you'd like me to.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
begin 666 scope_guard.zip M4$L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FFQ\DFB;A M=5-X?Y@2*%G=O@KT?]2 FX0W31GX<<NFY(9\:S&&E2^0+UP6\D4,9&M9_/VT M_J5MS:GZ;4+=L?Z+B)I;V8\":\Z-;Y77NT7U[;7\T^__`%!+`0(4`!0``@`( M`'0$%C.MBH8`&PD``,(N```-````````````( ````````!S8V]P95]G=6%R 99"YH4$L%!@`````!``$`.P```$8)```````` ` end

"Andrey Semashev" wrote:
I purpose to add a generalized scope guard classes to the Boost library. I have a rather simple but flexible implementation of such classes (I've attached the sources). Since I'm new here, I don't really know if they conform some source code conventions in Boost (if any), but if they don't - please, let me know.
I was not able to extract the code (could you add it as attachment or put it into Sandbox?) but FYI: One ScopeGuard implementation (practically copy of Alexandrescu's one) exists inside Multi-Index library (boost/multi_index/detail/scope_guard.hpp). It was intended as "temporary" solution "until someone creates full-features Boost library". ---- A very interesting Scope Guard variant can be found in TnFox library: http://tnfox.sourceforge.net/TnFOX/html/group__rollbacks.html /Pavel

Even more historical proposals are here: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?WantedLibrari... /Pavel

"Pavel Vozenilek" <pavel_vozenilek@hotmail.com> wrote in message news:deb674$oa0$1@sea.gmane.org...
"Andrey Semashev" wrote:
I purpose to add a generalized scope guard classes to the Boost library. I have a rather simple but flexible implementation of such classes (I've attached the sources). Since I'm new here, I don't really know if they conform some source code conventions in Boost (if any), but if they don't - please, let me know.
I was not able to extract the code (could you add it as attachment or put it into Sandbox?) but FYI:
Actually, I tried to attach it to my first posting, sadly, unsuccessfully. I tried once more in my reply to David, it should be okay this time.
One ScopeGuard implementation (practically copy of Alexandrescu's one) exists inside Multi-Index library (boost/multi_index/detail/scope_guard.hpp).
It was intended as "temporary" solution "until someone creates full-features Boost library".
Yes, I've considered the multi_index (Alexandrescu) version and the main purposes I've opened this thread are: - The multi_index version is in "detail" area, so a user cannot safely use it. Theoretically speaking, it may be modified or even removed in future versions. - The implementation I described has some advantages comparing to multi_index one (namely, exception handling support and construction functor execution). In a simpliest case it is rather similar to multi_index one. On the other hand, the advantage of the multi_index version is emulating bind/mem_fn functions for several functor arguments and a possibility of not using boost::funcion, which gives some perfomance gain. To my mind, it might be better to make a mixed solution, with blended functionality and optimization. The only nasty thing will be excessive template parameters number (the drawback I tried to avoid when I was designing my version).
A very interesting Scope Guard variant can be found in TnFox library: http://tnfox.sourceforge.net/TnFOX/html/group__rollbacks.html
Yes, a rather interesting guards application. But from that point if view scope guards are not simply scope guards but a transaction support mechanism. Speaking frankly, I haven't thought of it that way yet. Anyway, such mechanism may be done with entering-and-leaving scope guard. And guard collections is another god idea.
/Pavel
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (3)
-
Andrey Semashev
-
David Abrahams
-
Pavel Vozenilek