
On 7/8/07, I Wei <i.c.code@gmail.com> wrote:
On 7/9/07, Peter Dimov <pdimov@pdimov.com> wrote:
I Wei wrote:
With the boost::function<>::argN_type I can get boost::function's argument type. How can I do with the boost::lambda_functor?
You can't because there is no such thing. A lambda functor such as _1 + 2 can accept (almost) any argument x for which x+1 makes sense. What are you trying to do?
This is my situation: [snip]
template <typename T1, typename T2> void func(int n, T2 f) { typedef typename T2::arg1_type arg1_type;
getter< boost::is_same< arg1_type, boost::shared_ptr<T1> >::value >do_get<T1, boost::function<void(arg1_type)> >(n, f); } [snip] But there are a lot of similar calls with different second template argument, I want the compiler deduce it by the caller function's actual argument. How can I do that?
I'm just guessing here (your example never actually invokes the lambda functor), but I think you want to change func above to something like... template <typename T1, typename T2> void func(T1 n, T2 f) { typedef T1 arg1_type; // ... } ... if you want to deduce the type of n. I am not sure that you need to use boost::function at all. Also, this seems like a very convoluted way of dispatching a function based on whether or not it's called with a smart pointer. Why not overload do_get for smart_pointer rather than specializing getter for the value of is_same? Daniel