Boost logo

Boost :

From: Eugene Lazutkin (eugene_lazutkin_at_[hidden])
Date: 2003-07-19 12:30:15


"Ross Smith" <r-smith_at_[hidden]> wrote in message
news:200307191124.21290.r-smith_at_ihug.co.nz...
>
> This is easily handled; just use boost::bind(ReleaseDC, hWindow, _1) for
> the release function.

In proposed library release functionality is handled by static function,
which is part of trait:

struct win_file_handle {
    typedef HANDLE handle_type;
    static bool is_valid(handle_type h) { return h != INVALID_HANDLE_TYPE; }
    static void release(handle_type h) { if (is_valid(h))
::CloseHandle(h); }
    static handle_type default_value() { return INVALID_HANDLE_TYPE; }
    static bool equal(handle_type lhs, handle_type rhs) { return lhs==rhs; }
};

(This example is taken from original post by John Madsen.)

Obviously this approach doesn't provide for solution proposed by you because
hWindow is unknown until run time. One obvious way is to have release
function as constructor parameter, which is going to be called during
destruction. In this case we can use a lot of nifty stuff including binding.
Is it good solution? Well, it depends. In some cases it would be too much of
overhead.

Thanks,

Eugene


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk