Boost logo

Boost :

From: Dirk Gerrits (dirkg_at_[hidden])
Date: 2002-05-12 12:21:50


> I shouldn't have said "it would be possible" but been a little more
cautious
> and said "it might be possible". There are a few tricks that might be
usable,
> e.g., the has_member idea (it's in the archives) could probably be applied
> like this:
>
> template<bool Cond> struct yes
> {
> typedef void* type;
> };
>
> template<> struct yes<false>
> {
> // no type typedef
> };
>
> template<typename R, typename T1, ..., typename TN>
> class function {
> public:
> template<typename F>
> function(F f,
> typename yes<is_callable<F, R, T1, ..., TN>::value>::type = 0);
>
> // ...
> };
>
> The idea being that if F is callable, yes<true>::type will be void* and
> everything is okay. However, if F is not callable then yes<true>::type
does
> not even exist so the constructor cannot be instantiated.
>
> This worked in a little proof-of-concept test.

This is neat! Thanks a lot. Too bad I can't use it at the moment.

> The next step is to work on is_callable. I know that the following cases
can
> be handled:
> - function pointers
> - member function pointers
> - anything derived from std::unary_function or std::binary_function
> - anything that has function object traits and is not partially bound
>
> I don't know if is_callable can be written to handle arbitrary function
> objects.

Well good luck with your research. It would really be a cool addition to
Boost.
But I don't really see how this could work at all without partial
specialization.
(Workarounds for partial specialization can't do the job in this case
AFAIK.)
BTW, in contrast to my make_function, this is_callable template could be
made
to work with the result of a Boost.Bind right? (And Boost.Lambda???)

Dirk Gerrits


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk