title: generating huge Boost.MPL type sequences
body: <p>Consider the following code that automates generation of Boost.MPL type sequences (list or vector). </p>
  
  <pre><code>    #include &lt;iostream&gt;                     // cout
      #include &lt;boost/mpl/for_each.hpp&gt;       // for_each
      #include &lt;boost/mpl/identity.hpp&gt;       // identity, make_identity
      #include &lt;boost/mpl/int.hpp&gt;            // int_
      #include &lt;boost/mpl/list.hpp&gt;           // list
      #include &lt;boost/mpl/next.hpp&gt;           // next
      #include &lt;boost/mpl/push_front.hpp&gt;     // push_front
      #include &lt;boost/mpl/vector.hpp&gt;         // vector
  
      template&lt;size_t, typename&gt; struct iota_n;
  
      template&lt;typename Value&gt;
      struct iota_n&lt;0, Value&gt;
      :
              boost::mpl::list&lt;&gt;      // can change this to boost::mpl::vector&lt;&gt;
      {};
  
      template&lt;size_t N, typename Value&gt;
      struct iota_n
      :
              boost::mpl::push_front&lt; typename
                      iota_n&lt; 
                              N - 1, typename
                              boost::mpl::next&lt;Value&gt;::type
                      &gt;::type,
                      Value
              &gt;
      {};
  
      // works for N &lt;=  20 and boost::mpl::vector
      // works for N &lt;= 247 and boost::mpl::list
      typedef iota_n&lt; 247, boost::mpl::int_&lt;0&gt; &gt;::type sequence;
  
      struct print
      {
              template&lt;typename T&gt;
              void operator()(boost::mpl::identity&lt;T&gt;)
              {
                      std::cout &lt;&lt; T::value &lt;&lt; "\n";
              }
      };
  
      int main()
      {
              boost::mpl::for_each&lt;sequence, boost::mpl::make_identity&lt;&gt; &gt;(
                      print()
              );
              std::cout &lt;&lt; BOOST_MPL_LIMIT_LIST_SIZE &lt;&lt; '\n';         // 20 on my system
              std::cout &lt;&lt; BOOST_MPL_LIMIT_VECTOR_SIZE &lt;&lt; '\n';       // 20 on my system
              return 0;
      }
  </code></pre>
  
  <p>According to the Boost.MPL documentation, a <code>boost::mpl::list</code> sequence can have up to <code>BOOST_MPL_LIMIT_LIST_SIZE</code> elements, and similarly for a <code>boost::mpl::vector</code> the compiler can go up to <code>BOOST_MPL_LIMIT_VECTOR_SIZE</code>. Both macros evaluate to 20 on my system.</p>
  
  <p>MSVC++ 2010 and Boost 1.47.0 indeed cannot generate vectors with more than the documented 20 elements. What is surprising that it can, however, generate lists with up to 247 elements! </p>
  
  <p>Does anyone know why this happens? </p>