|
Boost Users : |
Subject: [Boost-users] A MPL loop..
From: Frank Winter (frank.winter_at_[hidden])
Date: 2010-07-11 03:18:27
I am trying to translate this runtime loop
while( totalsize * maxelem * 3 > poolsize )
maxelem >>= 1;
into MPL. I got so far:
template< typename totalsize , typename maxelement , typename poolsize >
struct loop
{
typedef mpl::times< totalsize , maxelement > part0;
typedef mpl::times< part0 , mpl::int_< 3 > > part1;
typedef mpl::greater< part1 , poolsize > gr;
typedef mpl::if_< gr , typename loop< totalsize , mpl::divides< maxelement ,
mpl::int_< 2 > > , poolsize >::value , maxelement > value;
};
template< class totalsize , class poolsize >
struct loop< totalsize , mpl::int_< 1 > , poolsize >
{
typedef mpl::int_< 1 > value;
};
typename loop< mpl::int_< 144 > , mpl::int_< 1024 > , mpl::int_< 140000 >
> ::value max;
g++43 (GCC) 4.3.2 says:
error: template instantiation depth exceeds maximum of 500
If coded it correctly that should not happen. Since maxelement is already after
the 1st interation mpl::int_< 512 > and therefor the product with
mpl::int_< 144 > smaller than mpl::int_< 140000 >
I could imagine:
- that I need a constructor that converts the divided types, correct?
- that I need to use a vector< sequence > like in the physics dimension
example, correct?
Can somebody fix this or point me to a working loop example?
Regards,
Frank
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net