Re: how to ensure loop unrolling with template programming

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12 July 2010 06:25, Frank Winter <frank.winter@xxxxxxx> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux