|
Boost : |
From: Brock Peabody (brock.peabody_at_[hidden])
Date: 2005-07-18 10:19:00
Hi,
I'm trying to learn how to make my own lambda compatible function
objects and I'm hoping that someone can nudge me in the right direction.
My first try is called tuple_element. It takes an index as a template
parameter and a tuple as an argument, returning the element at the given
index:
//should print "x"
cout << tuple_element<1>(_1)(tuple<int,std::string>(2, "x"));
I've got everything working except for the sig template. tuple_element
looks like (mostly copied from lambda source code):
template <int Index> struct tuple_element_action {};
template <int Index, typename Arg>
inline const
lambda_functor<
lambda_functor_base<
tuple_element_action<Index>,
tuple<lambda_functor<Arg> >
>
>
tuple_element(const lambda_functor<Arg>& a) {
return
lambda_functor_base<
tuple_element_action<Index>,
tuple<lambda_functor<Arg> >
>
( tuple<lambda_functor<Arg> >(a));
}
and the action:
template<typename Args, int Index>
class
lambda_functor_base<tuple_element_action<Index>, Args> {
public:
Args args;
template <class T> struct sig : tuples::element<Index,T>
{};
explicit lambda_functor_base(const Args& a) : args(a) {}
template<class RET, CALL_TEMPLATE_ARGS>
RET call(CALL_FORMAL_ARGS) const {
return detail::select(get<0>(args),
CALL_ACTUAL_ARGS).get<Index>();
}
};
When I try to compile my example in VC 7.1 I get an error that seems to
indicate that the type being passed to the sig template is
boost::tuples::null_type. Everything works if I hardwire it like:
template <class T> struct sig { typedef std::string type; };
Any ideas?
Thanks,
Brock
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk