Hi All,
This is a newbie mpl question, and here goes:
How can evaluate integer powers using mpl? Such as,
template < unsigned Pow,
class Real > Real pow( Real r )
{
return <compile time r*r*r* ... r > ;
// the expression is compile time,
// not the result of course.
}
int main()
{
float k = pow<6>(3.14f);
return k; // just kidding :)
}
An also as a side question, is there a wrapper type container (or iterator?) that holds a given constant value (or type)? Such as, the aptly named "constant_wrapper" used below with fold algorithm,
using namespace boost::mpl;
const unsigned SIZE = 5;
typedef fold <
constant_wrapper< int_<-3>, SIZE>
, int_<0>
, plus<_,_>
>::type number;
BOOST_STATIC_ASSERT( number::value == -3*SIZE );
Thanks a lot