|
Boost Users : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-10-31 16:55:38
On Thursday 31 October 2002 01:22 pm, hugo duncan wrote:
> Is this possible? if so what signature should the function have ?
> //! this works fine passing a boost::function object
> template <class ReturnType>
> void add(const boost::function1<ReturnType,ObjectType>& arg)
> {
> boost::function1<ReturnType,ObjectType> fn_obj=arg;
> }
Generally speaking, it's not useful to have any of the template arguments to a
Boost.Function object deduced, because it won't work the way you want it to.
> //! this should work when passed the result of a boost::bind
> template <class ReturnType>
> void add(?what goes here? & arg)
> {
> function1<ReturnType,ObjectType> fn_obj(arg);
> }
> };
You could take the function object as a template paramter and extract its
result_type:
template<typename F>
void add(F arg)
{
typedef typename F::result_type ReturnType;
function1<ReturnType,ObjectType> fn_obj(arg);
}
Doug
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net