[Assorted-commits] SF.net SVN: assorted:[1096] cpp-commons/trunk/src/commons/boost/delegates.h
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-12-07 08:18:15
|
Revision: 1096 http://assorted.svn.sourceforge.net/assorted/?rev=1096&view=rev Author: yangzhang Date: 2008-12-07 08:18:08 +0000 (Sun, 07 Dec 2008) Log Message: ----------- added finally Modified Paths: -------------- cpp-commons/trunk/src/commons/boost/delegates.h Modified: cpp-commons/trunk/src/commons/boost/delegates.h =================================================================== --- cpp-commons/trunk/src/commons/boost/delegates.h 2008-12-06 23:04:40 UTC (rev 1095) +++ cpp-commons/trunk/src/commons/boost/delegates.h 2008-12-07 08:18:08 UTC (rev 1096) @@ -48,6 +48,20 @@ // catch (std::exception &ex) { return std::exception(ex); } // } + /** + * A class that takes a functor and calls it on destruction, effectively + * giving you a `finally` clause. Particularly useful with clamp. + */ + //template<typename T> + typedef function0<void> T; + class finally { + public: + finally(T f): f_(f) {} + ~finally() { f_(); } + private: + T f_; + }; + } #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |