|
Boost : |
From: Doug Gregor (gregod_at_[hidden])
Date: 2001-04-09 22:05:36
On Monday 09 April 2001 03:43, you wrote:
> At Mon, 9 Apr 2001 08:42:48 -0400,
>
> Doug Gregor wrote:
> > ------------------------------
> > Interface summary:
> >
> > template<typename Result, typename Arg1, typename Arg2, ..., typename
> > ArgN> class any_function
> > {
> > any_function();
> > any_function(const any_function&);
> > template<typename Functor> any_function(Functor);
> > ~any_function();
> >
> > any_function& operator=(const int); // assignment to zero clears
> > target template<typename Functor> any_function& operator=(Functor);
> > any_function& operator=(const any_function&);
> >
> > void clear(); // clear out the target
> >
> > bool empty() const; // true if no target
> > operator const void*() const; // evaluates true if non-empty
> >
> > Result operator()(Arg1, Arg2, ..., ArgN); // call target
> > };
> > -------------------------------
> >
> > Doug
>
> Here are my two cents:
>
> Could be there is speicalized versions of any_function class which
> take a function pointer type template argument and deduce other types
> from it ?
It is possible, though I don't know that it could be done portably because it
would (likely) require either partial specialization (not always available)
or a working is_function (I don't believe is_function works on all platforms).
> template <class Fp>
> class any_function<function_traits<Fp>::return_type,
> function_traits<Fp>::Arg1,
> function_traits<Fp>::Arg2,
> ...>
> {
> any_function(Fp fp_);
>
> //...
> }
I'm not entirely sure what you are getting at here. The above template can't
ever be selected because all of the parameters used in the specialization
(i.e., typename function_traits<Fp>::return_type) can't deduce Fp.
> Or maybe a set of functions:
>
> template <class Fp>
> function_traits<Fp>::return_type
> eval_function(Fp fp);
>
> template <class Fp>
> function_traits<Fp>::return_type
> eval_function(Fp fp, function_traits<Fp>::Arg1 arg1);
>
> template <class Fp>
> function_traits<Fp>::return_type
> eval_function(Fp fp, function_traits<Fp>::Arg1 arg1,
> function_traits<Fp>::Arg2);
>
> //more to take more arguments.
>
>
> In fact, I am using the latter to create threads in my code.
What additional power do the eval_function functions give you over just:
Fp fp;
fp(arg1, arg2, ..., argN);
?
I can see some usefulness of, for instance, a "make_function" helper function
that is defined as:
template<typename R, typename T1, typename T2, ..., typename TN>
any_function<R, T1, T2, ..., TN>
make_function (R (*f)(T1, T2, ..., TN)) { /* ... */ }
But even in this case, would it be more useful just to pass the original
function (object/pointer)?
Doug
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk