|
Boost : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-05-11 10:15:09
On Saturday 11 May 2002 09:12 am, you wrote:
> I appreciate your input, and this is indeed another way to look at the
> problem. But I don't really thing it is easier to write ArietyTrait than
> it is to write make_function. (It might be more reusable though???)
>
> Also, I forgot to mention that I'm using MSVC6 so no partial
> specialization.
>
> :(
>
> Dirk Gerrits
You can do the same without partial specialization using function overloading:
template<typename R>
inline boost::function0<R> make_function(R (*f)())
{ return boost::function0<R>(f); }
template<typename R, typename T1>
inline boost::function1<R, T1> make_function(R (*f)(T1))
{ return boost::function1<R, T1>(f); }
template<typename R, typename T1>
inline boost::function1<R, T1> make_function(R (T1::*f)())
{ return boost::function1<R, T1>(f); }
// etc...
Of course, this style only works for free and member functions. We'd need
something like ArityTraits to handle arbitrary function objects. That's the
reason that make_function never really made it: we don't have a good set of
function object traits to work with.
If we _did_ have a working set of function traits, it would be possible to
make Boost.Function objects implicitly constructed only from function objects
that are callable by the Boost.Function object.
Doug
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk