title: Template-ing a 'for' loop in C++?
body: <p>I have a C++ snippet below with a run-time <code>for</code> loop,</p>
  
  <pre><code>for(int i = 0; i &lt; I; i++)
    for (int j = 0; j &lt; J; j++)
      A( row(i,j), column(i,j) ) = f(i,j);
  </code></pre>
  
  <p>The snippet is called repeatedly. The loop bounds 'I' and 'J' are known at compile time (I/J are the order of 2 to 10). I would like to unroll the loops somehow using templates. The main bottleneck is the row() and column() and f() functions. I would like to replace them with equivalent metaprograms that are evaluated at compile-time, using <code>row&lt;i,j&gt;::enum</code> tricks.</p>
  
  <p>What I'd really love is something that eventually resolves the loop into a sequence of statements like:</p>
  
  <pre><code>A(12,37) = 0.5;
  A(15,23) = 0.25;
  A(14,45) = 0.25;
  </code></pre>
  
  <p>But I'd like to do so without wrecking the <code>for</code>-<code>for</code> structure too much. Something in the spirit of:</p>
  
  <pre><code>TEMPLATE_FOR&lt;i,0,I&gt;
    TEMPLATE_FOR&lt;j,0,J&gt;
       A( row&lt;i,j&gt;::value, column&lt;i,j&gt;::value ) = f&lt;i,j&gt;::value
  </code></pre>
  
  <p>Can boost::lambda (or something else) help me create this?</p>