Hi,
After I discovered Boost.Fusion I realize that I can define proper
named functions with Boost.Fusion. Named in the sense of
instrospection (not in the sense of default user parameters). It was
something that is easy to achieve but it was very verbose. I
simplified a little bit the syntax but at the end I got stuck just
before achieving something useful with this ideas. I need a little
help towards the end.
using namespace boost::fusion;
double H(double p, double q){ // original function for reference
return p*p + q*q;
}
struct p{};
struct q{};
double H(map (1.,2.));
and worked!
On the side of the function definition I can have an alternative
syntax which may be shorter but more difficult to interpret:
double H(result_of::make_map ::type const& args)
{ ... }
although it is not a great improvement.
Second question: Does it occur to anyone how simplify things further?
This is nice because *in principle* I can distinguish between the two
parameters (strictly speaking is all one big parameter) at compile
time via templates.
Third question: I say in principle because I am stuck here. For
example how can I implement a named parameter bind? It seems to me
that I am close to achieving this but I don't know exactly how. What I
want is some kind of "bind > const& args){
return H(at_key<p>(args), at_key<q>(args));
}
int main(){
cout << H(
map
>(
make_pair<p>(1.),
make_pair<q>(2.)
)
);
return 0;
}
One question: Why I can not interchange the order of p and q in the
last call, after all it is a map at the library could in principle
differentiate the pairs? making it possible to call an unordered named
parameter. e.g.
cout << H(
map
>(
make_pair<q>(2.), // was p
make_pair<p>(1.) // was q
)
);
Is it possible to interchange the order to give more flexibility to
the user?
After a little playing I gladly found that the make_pair is not
stricly necesary
cout << H(
map
>(1.,2.)
);
which is a nice improvement. It seems that still there is some
redundancy, so I tried
cout << H(make_map