|
Boost : |
From: Jonathan Wakely (cow_at_[hidden])
Date: 2004-12-29 10:06:41
On Wed, Dec 29, 2004 at 04:44:22PM +0200, Peter Dimov wrote:
> Jonathan Wakely wrote:
> > struct DCReleaser
> > {
> > DCReleaser(HWND hwnd) : hwnd(hwnd) {}
> > void operator()(void* p) { ReleaseDC( hwnd, (HDC)p ); }
> > HWND hwnd;
> > };
> >
> > handle make_dc( HWND hWnd )
> > {
> > return handle( GetDC( hWnd ), DCReleaser(hWnd) );
> > }
>
> Yep. Note also that shared_ptr will call the deleter with an HDC, not a
> void*, so the cast in operator() is not necessary:
>
> void operator()(HDC p) const { ReleaseDC( hwnd, p ); }
Yes, of course it will. Silly me. Thanks, Peter.
> >I think bind(ReleaseDC, hWnd, _1) should work.
>
> That's what I'd use, too. :-)
Finally, Dirk, if you don't want to use shared_ptr<void> (and casts)
everywhere you can include boost/type_traits.hpp and use remove_pointer:
typedef shared_ptr<remove_pointer<HDC>::type> dc_handle;
typedef shared_ptr<remove_pointer<HWND>::type> wnd_handle;
jon
-- "It is unbecoming for young men to utter maxims." - Aristotle
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk