|
Boost : |
From: I Wei (i.c.code_at_[hidden])
Date: 2007-07-08 20:37:09
On 7/9/07, Peter Dimov <pdimov_at_[hidden]> 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:
#include "boost/function.hpp"
#include "boost/lambda/bind.hpp"
#include "boost/shared_ptr.hpp"
template <bool b>
struct getter
{
template<typename T1, typename T2>
void do_get(int n, T2 f)
{
// do something;
}
};
template <>
struct getter<true>
{
template<typename T1, typename T2>
void do_get(int n, T2 f)
{
// do something else;
}
};
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);
}
class Foo
{
};
void foo(int n, Foo t)
{
}
int main()
{
func<Foo>(1, boost::lambda::bind(&foo, 0, boost::lambda::_1));
return 0;
}
because the boost::lambda::bind return a lambda_functor, the "
typedef typename T2::arg1_type arg1_type;" is wrong, if I add the
second template argument to the caller func as func<Foo,
boost::function<void(Foo)> >, everything will be ok. 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?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk