
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

AMDG Frank Winter wrote:
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; };
Try using eval_if so you don't recurse forever. I would also suggest extracting the ::type from mpl::divides, so that the type doesn't grow indefinitely. You also need to get the ::type out of mpl::if_.
template< class totalsize , class poolsize > struct loop< totalsize , mpl::int_< 1 > , poolsize > { typedef mpl::int_< 1 > value; };
This specialization won't work, since mpl::divides<...> is not the same type as mpl::int_<1>. In Christ, Steven Watanabe

Thanks for your reply!
I tried to add your suggestions. Now the compilation doesn't seem to
be able to pass struct loop. Error message:
meta.cc:31: error: type/value mismatch at argument 2 in template parameter
list for 'template
AMDG
Frank Winter wrote:
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; };
Try using eval_if so you don't recurse forever. I would also suggest extracting the ::type from mpl::divides, so that the type doesn't grow indefinitely. You also need to get the ::type out of mpl::if_.
template< class totalsize , class poolsize > struct loop< totalsize , mpl::int_< 1 > , poolsize > { typedef mpl::int_< 1 > value; };
This specialization won't work, since mpl::divides<...> is not the same type as mpl::int_<1>.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

AMDG Frank Winter wrote:
meta.cc:31: error: type/value mismatch at argument 2 in template parameter list for 'template
struct boost::mpl::eval_if' meta.cc:31: error: expected a type, got 'loop::value' I marked line 31 with an asterix.
Any further ideas? template< typename totalsize , typename maxelement , typename poolsize > struct loop { typedef typename mpl::times< totalsize , maxelement >::type part0; typedef typename mpl::times< part0 , mpl::int_< 3 > >::type part1; typedef typename mpl::greater< part1 , poolsize >::type gr; typedef typename mpl::divides< maxelement , mpl::int_< 2 > >::type maxelement2; * typedef typename mpl::eval_if< gr , loop< totalsize , maxelement2 , poolsize >::value , maxelement >::type value;
typedef typename mpl::eval_if< gr , loop< totalsize , maxelement2 , poolsize >, maxelement >::type type; In Christ, Steven Watanabe

On 07/11/10 02:18, Frank Winter wrote:
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 You might try using:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/mpl/while.hp... or maybe the while_recur template used here: https://svn.boost.org/trac/boost/attachment/ticket/3044/while_recur.cpp

On 07/11/10 10:39, Larry Evans wrote:
On 07/11/10 02:18, Frank Winter wrote:
I am trying to translate this runtime loop
while( totalsize * maxelem * 3 > poolsize ) maxelem >>= 1;
into MPL. I got so far:
[snip] You might try using:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/mpl/while.hp...
[snip] The attached uses mpl/while.hpp, giving output: actual result=256 expected result=256
participants (3)
-
Frank Winter
-
Larry Evans
-
Steven Watanabe