Listing 12
// Nested loops with For<>
// templates for inner loop
template<typename state>
struct incr_in { ... };
template<typename state>
struct cond_in { ... };
// templates for outer loop
template<typename state>
struct incr_out { ... };
template<typename state>
struct cond_out { ... };
// body of inner loop (i.e one iteration)
template <typename state >
struct body
{
typedef state result;
static void exec() { ... };
};
// simulate template typedef (a feature forthcoming in C++0x)
template <typename T>
struct inner_loop
{
typedef T result;
static void eval() {
For_< cond_in, incr_in, body, T>::exec();
}
};
// nest "inner_loop" into For<>
For_< cond_out, incr_out, inner_loop, state<...> >::eval() ;