|
Boost Users : |
Subject: Re: [Boost-users] extraction invariants from intensive-loop based on template parameters
From: Hicham Mouline (hicham_at_[hidden])
Date: 2009-02-19 09:33:39
> ----- Original Message -----
> From: "Matthieu Brucher" <matthieu.brucher_at_[hidden]>
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] extraction invariants from intensive-loop based on template parameters
> Date: Thu, 19 Feb 2009 14:17:20 +0100
>
>
> Hi,
>
> The compiler is smart enough to prune an if condition if it knows that
> the value is always false.
> So if you add an if(!Lower::IsConstant) before and after your loop,
> you don't have to rewrite it.
>
> Matthieu
>
> 2009/2/19 Hicham Mouline <hicham_at_[hidden]>:
> > Hello,
> >
> > I have an algorithm like:
> >
> > template <typename Upper, typename Lower>
> > class X {
> >
> > static void f()
> > {
> > ....
> > for (size_t n=0; n<=N; ++n)
> > {
> > // process for j=0 at every n if Lower::IsConstant is false
> > for (size_t j=1; j<=J-1; ++j)
> > {
> > }
> > // process for j=J at every n if Upper::IsConstant is false
> > }
> > ....
> > }
> >
> >
> > So I extracted the double for loop in a separate wrapper class and
> > I verbosely wrote 4 specializations with template args begin bool :
> >
> > <true, true>
> > <false, true>
> > <true, false>
> > <false, false>
> >
> > for e.g. for <true, true>
> >
> > // process for j=0 once
> > for (size_t n=0; n<=N; ++n)
> > {
> > for (size_t j=1; j<=J-1; ++j)
> > {
> > }
> > }
> > // process for j=J once
> >
> >
> > Any advice?
> > Is there a better way than writing explicitly the tmpl specializations?
> > Boost.PP maybe?
> >
> > rds,
> > _______________________________________________
I've just measured with VS2005, g++4.0 and intel11.
At least these 3 compilers are smart enough.
Thanks,
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