how to ensure loop unrolling with template programming
me22
me22.ca@gmail.com
Tue Jul 13 00:36:00 GMT 2010
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
More information about the Gcc-help
mailing list