|
Boost Users : |
Subject: Re: [Boost-users] A MPL loop..
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-07-11 11:03:57
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 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