|
Boost Users : |
Subject: Re: [Boost-users] Is there a portable way to determine whether a type is functor ?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-12-26 17:56:43
AMDG
ancode tran wrote:
> Hi all,
>
> The following code only works under g++ 4.x:
>
> #include <boost/type_traits.hpp>
>
> template <class T>
> struct is_functor_helper
> {
> static boost::type_traits::no_type test (...);
> template <class U>
> static boost::type_traits::yes_type test (U*, typeof(&U::operator()) dummy = NULL);
> BOOST_STATIC_CONSTANT (bool, value = sizeof(test((T*)NULL)) == sizeof(boost::type_traits::yes_type));
> };
>
> template <class T> struct is_functor: public boost::integral_constant<bool, is_functor_helper<T>::value> { };
>
> Can anyone give me a hint to make it work under other toolset, please ?
> Thanks in advance.
>
That won't work with an overloaded or templated operator().
In general, there is no way to determine whether an operator() exists.
If you want to determine whether a type can be called with particular
parameters see
http://www.boost.org/doc/html/proto/appendices.html#boost_proto.appendices.implementation.function_arity
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