Boost logo

Boost Users :

From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-04-25 18:32:15


AMDG

Robert Dailey wrote:
>
>
> If you only need to deal with function pointers,
>
> template<class T>
> void Subscribe(void (*callback)(const packet_t&)) {
> Subscribe(boost::function<void(const packet_t&)>(callback));
> }
>
>
> What about for function objects?

There is no way to deduce what a function object can be called with
since it can have an overloaded operator(). To deal with monomorphic
unary function objects that follow the std library conventions, use this:
(warning untested.)

BOOST_MPL_HAS_XXX_TRAIT_DEF(argument_type);

template<class T>
typename boost::enable_if<has_argument_type<T> >::type
Subscribe(const T& t) {
    Subscribe(boost::function<void(const typename
boost::remove_cv<typename boost::remove_reference<typename
T::argument_type>::type>::type&)>(callback));
}

In Christ,
Steven Watanabe


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