[boost.bind] How to retrieve the function type of a boost::bind result

Hi,
The following snippet won't compile since the compiler can't deduce the
template argument:
template<typename T>
void foo(boost::function<T> func) { /*...*/ }
void bar() {}
void baz()
{
foo(boost::bind(&bar)); // error
foo

AMDG Olaf Krzikalla wrote:
The following snippet won't compile since the compiler can't deduce the template argument:
template<typename T> void foo(boost::function<T> func) { /*...*/ }
void bar() {}
void baz() { foo(boost::bind(&bar)); // error foo
(boost::bind(&bar)); // OK foo(boost::function (boost::bind(&bar))); // OK } So how do I get the first line of baz to work? That is, is there a generic way to compute the boost::function type from the bind result?
There is not because the boost::function type is not unique. Consider: struct F { typedef void result_type; template<class T> void operator()(const T&) const; }; boost::bind(F(), _1); In Christ, Steven Watanabe

Hi, Steven Watanabe wrote:
Olaf Krzikalla wrote:
template<typename T> void foo(boost::function<T> func) { /*...*/ }
void bar() {}
void baz() { foo(boost::bind(&bar)); // error }
So how do I get the first line of baz to work? That is, is there a generic way to compute the boost::function type from the bind result?
There is not because the boost::function type is not unique.
Hmm, indeed. However wouldn't it be possible for the bind (member) function pointer overloads to return a "_bind_t_ex" type derived from _bind_t containing a function_type typedef? In my particular use case I will use bind with function pointers only. Best regards Olaf Krzikalla

Olaf Krzikalla: ...
template<typename T> void foo(boost::function<T> func) { /*...*/ }
void bar() {}
void baz() { foo(boost::bind(&bar)); // error }
So how do I get the first line of baz to work? That is, is there a generic way to compute the boost::function type from the bind result?
There is not because the boost::function type is not unique. Hmm, indeed. However wouldn't it be possible for the bind (member) function pointer overloads to return a "_bind_t_ex" type derived from _bind_t containing a function_type typedef? In my particular use case I will use bind with function pointers only.
In general you can't deduce a boost::function<> from the result of bind,
even if you only use functions.
function

Olaf Krzikalla:
template
struct arity_dispatch< boost::function > { static void call(const boost::function & f) { f(getArg<T>(0), getArg<T>(1)); } };
Why not dispatch on the number of arguments that are available via getArg? You won't then need to know the arity of the function object (assuming it has one and only one arity, which it may not.)

Why not dispatch on the number of arguments that are available via getArg? You won't then need to know the arity of the function object (assuming it has one and only one arity, which it may not.) I'm not sure if I understand you right. The top level problem is to bind C++ functions in a generic way to LUA
Hi,
Peter Dimov wrote:
script callbacks. That is I know the actual number of arguments not
before runtime. Below is my current solution (LUA specific stuff and the
rather obvious ArgTypeDispatcher are stripped):
---snip---
template<class T>
struct ArgNumDispatcher;
template<>
struct ArgNumDispatcher
participants (3)
-
Olaf Krzikalla
-
Peter Dimov
-
Steven Watanabe