This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: how to ensure loop unrolling with template programming


On 12 July 2010 06:25, Frank Winter <frank.winter@desy.de> wrote:
> Thanks for your reply!
>
> Your provided code doesn't seem to work:
>

It seems I out-clevered myself and ran into some nasty syntax corners.
 Here's a fixed version:

     template <unsigned I>
     struct repeater {
         template <typename F>
         repeater(F f) { f(); (repeater<I-1>)(f); }
     };

     template <>
     struct repeater<0> {
         template <typename F>
         repeater(F) {}
     };

     void bar() {
          std::cout << "Yay!\n";
     }

     int main() {
         (repeater<4>)(bar);
     }

Oh, the wonders of C++ grammar...

~ Scott


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]