|
Boost : |
From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2003-06-06 13:04:25
>From: "Bohdan" <gejrlaug_at_[hidden]>
> IMHO a very useful addon to your library can be routine
> to convert class to function which calls class destructor.
<snip>
> //no virtual functions, no runtime polymorphism
> void * ptr = new MyClass;
> destruct_fn_type df = destruct_fn<MyClass>();
>
> ....
> df(ptr);
Right. Your code works fine, and is also completely independent of
function_ptr, so might be useful as a utility in its own right. :)
Anyway, regarding function_ptr, as modern C++ typically is generic, so that
an entity only need to be "callable" (a function object or function
pointer), and that function objects also supports binding of parameters,
function_ptr probably have little use in modern C++.
When it comes to APIs that use function pointers, it also needs to be a C++
API, as function_ptr can't be used as an "extern "C"" function. Also, the OP
at the newsgroup prefers a macro to do this, after all, to avoid even
stating the function signature.
It was an interesting challenge, anyway. :)
Regards,
Terje
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk