I
i.c.code
maybe like:
#include "boost/function.hpp"
template <typename T>
class Do_When_Return
{
private:
Do_When_Return(const Do_When_Return&);
Do_When_Return();
Do_When_Return& operator=(const Do_When_Return&);
public:
Do_When_Return(boost::function<void (T)> f, T* p)
:func_(f)
,obj_(p)
{
}
~Do_When_Return()
{
if ( func_ && obj_ )
{
func_(*obj_);
}
}
private:
boost::function<void (T)> func_;
T* obj_;
};
so I can use it like this in some Windows GDI operations,
void test()
{
HDC hdc =GetDC(NULL);
Do_When_Return<HDC> auto_release_hdc(&ReleaseDC, &hdc);
//do something which use hdc
}
#include "boost/function.hpp"
template <typename T>
class Do_When_Return
{
private:
Do_When_Return(const Do_When_Return&);
Do_When_Return();
Do_When_Return& operator=(const Do_When_Return&);
public:
Do_When_Return(boost::function<void (T)> f, T* p)
:func_(f)
,obj_(p)
{
}
~Do_When_Return()
{
if ( func_ && obj_ )
{
func_(*obj_);
}
}
private:
boost::function<void (T)> func_;
T* obj_;
};
so I can use it like this in some Windows GDI operations,
void test()
{
HDC hdc =GetDC(NULL);
Do_When_Return<HDC> auto_release_hdc(&ReleaseDC, &hdc);
//do something which use hdc
}