|
Boost : |
From: Eric Lemings (lemings_at_[hidden])
Date: 2006-09-20 13:19:49
Currently, the integral constant wrappers (integral_c, int_, etc.) have
a function call operator that returns the runtime value of the type.
Naturally, the metafunctions for arithmetic operations inherit these
operators. Example:
typedef plus< int_<1>, int_<2> > t1;
assert (t1() == 3);
What if MPL took this a step further and extended the placeholders
concept to account for runtime parameters? The plus class template
would then have a function call operator that accepts zero or more
arguments depending on the number of placeholders. Some examples:
typedef plus< int<1>, _ > t2;
assert (t2(2) == 3);
typedef plus< _, _ > t3;
assert (t3(1, 2) == 3);
typedef plus< _, plus< _, int_<-1> > > t4;
assert (t4(1) == 1);
With a metafunction to count placeholders in a lambda expression and
some template specialization, I believe this is quite feasible. It
would be useful for combining MPL arithmetic operations into more
complex metafunctions that mix integral constants with runtime
arguments.
Thoughts?
Thanks,
Eric.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk