[phoenix] How to determine if a phoenix functor is callable?
So there any ways to implement a metafunction can_be_called on a phoenix functor s.t.: auto f = _1 + _2; static_assert(is_callable<decltype(f), double, double>::value, ""); static_assert(!is_callable<decltype(f), double, NonArithmeticType>::value, ""); static_assert(!is_callable<decltype(f), double>::value, ""); //Needs 2 args A while back, I was pointed towards the following from proto to determine if a functor was callable: http://www.boost.org/doc/libs/1_42_0/doc/html/proto/appendices.html#boost_pr... pendices.implementation.function_arity This seemed to work well for most of my custom built functors, but as far as I can tell, the trick doesn't work for either boost::lambda or boost::phoenix functors (or std::tr1::bind for that matter). I can post a test case for phoenix if people think that it should work. -Jesse
On 2/24/2010 10:36 PM, Jesse Perla wrote:
So there any ways to implement a metafunction can_be_called on a phoenix functor s.t.: auto f = _1 + _2; static_assert(is_callable<decltype(f), double, double>::value, ""); static_assert(!is_callable<decltype(f), double, NonArithmeticType>::value, ""); static_assert(!is_callable<decltype(f), double>::value, ""); //Needs 2 args
A while back, I was pointed towards the following from proto to determine if a functor was callable: http://www.boost.org/doc/libs/1_42_0/doc/html/proto/appendices.html#boost_pr... pendices.implementation.function_arity
This seemed to work well for most of my custom built functors, but as far as I can tell, the trick doesn't work for either boost::lambda or boost::phoenix functors (or std::tr1::bind for that matter). I can post a test case for phoenix if people think that it should work.
All phoenix callables are 'actors': template <typename Eval> struct actor; should be easy enough to detect. There is in fact something that you can use: template <typename T> struct is_actor; Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net http://www.facebook.com/djowel Meet me at BoostCon http://www.boostcon.com/home http://www.facebook.com/boostcon
Joel de Guzman <joel <at> boost-consulting.com> writes:
should be easy enough to detect. There is in fact something that you can use:
template <typename T> struct is_actor;
Thanks, that will be useful. But I also need to determine if the phoenix actor has an operator() that can be called with certain arguments. I will have a functor passed to my library that may be binary vs. trinary and I go down a different static code path depending on the case. Perhaps the detection of is_callable here is near impossible without SFINAE with expressions. But how about a simpler problem: double binary_func(double x, double y){return x;} double unary_func(double x){return x;} auto unary_f = bind(&unary_func, _1); auto binary_f = bind(&binary_func, _1, _2); auto binary_f2 = _1 + _2; static_assert(functor_arity<decltype(unary_f)>::value == 1, ""); static_assert(functor_arity<decltype(binary_f)>::value == 2, ""); static_assert(functor_arity<decltype(binary_f2)>::value == 2, ""); ... is there a way to get a count of placeholders in an actor, etc?
participants (2)
-
Jesse Perla
-
Joel de Guzman