
Hi Hicham, Hicham Mouline wrote:
Hello,
There are a few posts these days about generic libraries for math derivation of math functions, analytically or numerically.
<snip>
template <size_t dim =1> struct function_tag {};
Use MPL Integral Constants here instead: template<typename dim = mpl::size_t<1> > struct function_tag { typedef dim dimension; }; And define a dimension_of metafunction like this: template<typename FunTag> struct dimension_of { typedef typename FunTag::dimension type; };
I want to have 0 variables (nothing) for the 0-dim function in the proto::function case, and I want to have exactly dim variables in the dim>0 proto::function case.
Is it possible to “math-define” the function at the same time of the function<> object definition (in c++ terms) and have the dimension deducted, like:
function f(x,y,z) = x+y+z ;
Yes. Your LHS grammar should look something like this (untested): struct lhs_grammar : proto::or_< // lone functions are ok proto::terminal< function_tag< mpl::size_t<0> > > , proto::and_< // f(x,y,z,...) is ok ... proto::function< proto::terminal< function_tag< proto::_ > > , proto::vararg< proto::terminal< variable_tag > > > // ... as long as the dimension of the function // matches the number of arguments. , proto::if_< mpl::equal_to< dimension_of< proto::_value(proto::_child0) > , mpl::prior<proto::arity_of<proto::_> > >() > > > {}; HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com