title: Why is allocator::rebind necessary when we have template template parameters?
body: <p>Every allocator class must have an interface similar to the following:</p>
  <pre><code>template&lt;class T&gt;
  class allocator
  {
      ...
      template&lt;class Other&gt;
      struct rebind { typedef allocator&lt;Other&gt; other; };
  };
  </code></pre>
  <p>And classes that <em>use</em> allocators do something redundant like this:</p>
  <pre><code>template&lt;class T, class Alloc = std::allocator&lt;T&gt; &gt;
  class vector { ... };
  </code></pre>
  <p>But why is this necessary?</p>
  <p>In other words, couldn't they have just said:</p>
  <pre><code>template&lt;class T&gt;
  class allocator { ... };
  
  template&lt;class T, template&lt;class&gt; class Alloc = std::allocator&gt;
  class vector { ... };
  </code></pre>
  <p>which is both more elegant, less redundant, and (in some similar situations) potentially safer?<br />
  Why did they go the <code>rebind</code> route, which also causes more redundancy (i.e. you have to say <code>T</code> twice)?</p>
  <p>(Similar question goes to <code>char_traits</code> and the rest... although they don't all have <code>rebind</code>, they could still benefit from template template parameters.)</p>
  <hr />
  <h3>Edit:</h3>
  <blockquote>
  <h3>But this won't work if you need more than 1 template parameter!</h3>
  </blockquote>
  <p>Actually, it works very well!</p>
  <pre><code>template&lt;unsigned int PoolSize&gt;
  struct pool
  {
      template&lt;class T&gt;
      struct allocator
      {
          T pool[PoolSize];
  
          ...
      };
  };
  </code></pre>
  <p>Now if <code>vector</code> was only defined this way:</p>
  <pre><code>template&lt;class T, template&lt;class&gt; class Alloc&gt;
  class vector { ... };
  </code></pre>
  <p>Then you could just say:</p>
  <pre><code>typedef vector&lt;int, pool&lt;1&gt;::allocator&gt; int_vector;
  </code></pre>
  <p>And it would work perfectly well, <em>without</em> needing you to (redundantly) say <code>int</code> twice.</p>
  <p>And a <code>rebind</code> operation inside <code>vector</code> would just become <code>Alloc&lt;Other&gt;</code> instead of <code>Alloc::template rebind&lt;Other&gt;::other</code>.</p>