Loops, Metaloops, & C++
By Roshan Naik, August 01, 2004
Metaloops are implemented in C++ using recursive template instantiation. Roshan examines ideas around encapsulating metaloops and considers their usefulness.
August, 2004: Loops, Metaloops, & C++
Listing 5
// Nested metaloop initializing 5x6 array
template <int rows, int cols>
inline void elem_init (int arr[rows][cols], int i, int j)
{
arr[i][j] = rand();
}
int my_array[5][6];
Loop2<0,4, Loop2<0,5> >::eval( boost::bind(elem_init<5,6>,my_array,_1 ,_2) );