title: How do I store the intermediate results of a recursive function using C++ templates at compile time?
body: <p>I asked <a href="https://stackoverflow.com/questions/33252137/how-do-i-capture-the-results-of-a-recursive-function-at-compile-time">How do I capture the results of a recursive function at compile-time?</a>, but I think my approach was wrong.</p>
  
  <p>I have a program like so:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  
  std::list&lt;unsigned int&gt; recursive_case(std::list&lt;unsigned int&gt;&amp; result, unsigned int&amp; i) {
      result.push_front(1 + (i % 10));
      i /= 10;
      return i != 0 ? recursive_case(result, i) : result;
  }
  
  std::list&lt;unsigned int&gt; initial_case(unsigned int i) {
      std::list&lt;unsigned int&gt; result;
      result.push_back(i % 10);
      i /= 10;
      return i != 0 ? recursive_case(result, i) : result;
  }
  
  int main() {
      auto list = initial_case(123);
      bool first = true;
      for (auto i: list) {
          if (first) {
              first = false;
          } else {
              std::cout &lt;&lt; ", ";
          }
          std::cout &lt;&lt; i;
      }
      std::cout &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>The output is <code>2, 3, 3</code>.</p>
  
  <p>I want to perform the above computation and get the same output but in <strong>compile-time</strong> (the loop iteration and output-printing would be at runtime i.e. everything starting from the for loop). Templates seem like a possibility (that's why I tagged this ask as such), but I am open to anything that gets the job done in compile-time.</p>