|
Boost : |
From: Sohail Somani (s.somani_at_[hidden])
Date: 2007-01-20 20:39:57
Hi all,
A miniature project this week was started by me this week (I was bored?) to determine the minimum arity of a bind expression. On Peter's and Joel's suggestion, I made the changes non-intrusive: i.e. the listN's used to hold the argument sequence are fusion forward sequences. Currently there is no runtime component and I suspect there will need to be some generated "at" specializations, but I don't expect this to be too difficult. So anyway two-point-one questions:
1) How do I get the type of a bind expression as a metafunction (or something) so that I can have a metafunction (or something) to return the min_arity of a bind expression?
2) How do I make a patch that includes my added files? cvs diff only shows diffs to existing files
2.1) With 2) can someone help me make the fusion sequence a mpl sequence? I can't seem to get this to work properly
Thanks!
Sohail
PS: I'm a bit shaky on the whole metafunction concept as my attempts to get the mpl book were thwarted, hence the "or something" :) Go easy on me!
(Below is the current implementation of min_arity)
// TODO: make this into some sort of metafunction - or something
// probably will have to always have a function to deduce the bind
// expression type but the rest of it can probably be moved
template<int MinArity,typename BindExpression>
void min_arity(BindExpression const &)
{
// should be a meta function of some sort
typedef typename placeholders<BindExpression>::placeholders_list
placeholders_list;
// a list of... argument positions
typedef typename result_of::transform<
placeholders_list,
argument_position
>::type arg_positions;
// the maximum element
typedef typename mpl::max_element<
arg_positions>::type iter;
// if there are no placeholders
typedef typename result_of::empty<arg_positions>::type no_placeholders;
// can only dereference iterator if there were placeholders => atleast one argument position
typedef typename mpl::eval_if<
no_placeholders,
mpl::int_<0>,
mpl::deref<iter>
>::type min_arity_type;
BOOST_MPL_ASSERT(( boost::is_same<min_arity_type,mpl::int_<MinArity> >));
}
MPL_TEST_CASE()
{
min_arity<0>(boost::bind(&fn_0));
min_arity<5>(boost::bind(&fn_2,_4,_5));
min_arity<1>(boost::bind(&fn_1,_1));
int a=9;
min_arity<2>(boost::bind(&fn_3,a,_1,_2));
min_arity<3>(boost::bind(&fn_3,_1,_2,_3));
min_arity<4>(boost::bind(&fn_3,a,a,_4));
min_arity<9>(boost::bind(&fn_3,_7,_9,_8));
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk