$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Douglas Gregor (gregod_at_[hidden])
Date: 2001-10-07 15:44:02
On Sunday 07 October 2001 11:05, you wrote:
> I have encountered a situation where I have a boost::function:
>
> boost::function<void> onClick;
>
> initialized to a function object with a known type F (which is similar to a
> std::vector<boost::function<void> > with a broadcasting operator().)
>
> At some later point I need to ask onClick "do you contain an instance of F?
> if yes, please give me a reference to it so I can add another handler."
With the current interface, this isn't possible, but I think it would be a
worthwhile addition. I suggest the following interface (modeled after
boost::any)
template<typename R, typename T1, ..., typename TN>
class function {
public:
// type of target function object, or typeid(void) if empty
const std::type_info& type() const;
};
//
template<typename To, typename R, typename T1, ..., typename TN>
To& function_cast(function<R, T1, ..., TN>& f);
template<typename To, typename R, typename T1, ..., typename TN>
const To& function_cast(const function<R, T1, ..., TN>& f);
> Ideas?
I would think that onClick shouldn't be a boost::function<void>, but a
full-fledged signal. Unfortunately, we don't have one of those in Boost yet.
> BTW, the function documentation mentions 'operator bool' which has been
> replaced by 'operator safe_bool.'
It's an intentional trade-off. On one hand, the function documentation
out-and-out lies to the user about a conversion. On the other hand, the user
doesn't need to go look up what safe_bool is in the (nonexistant)
documentation.
safe_bool should go into utility.hpp, and then it would have documentation so
this problem would be avoided. I promised to do that but haven't yet
delivered :(.
> Also, operator! is not necessary.
It's a workaround. At least one compiler (Borland, perhaps?) doesn't find the
appropriate conversion sequence without an explicit operator!.
Doug