title: Why is the STL so heavily based on templates instead of inheritance?
body: <p>I mean, aside from its name <em>the Standard Template Library</em> (which evolved into the C++ standard library).</p>
  <p>C++ initially introduce OOP concepts into C. That is: you could tell what a specific entity could and couldn't do (regardless of how it does it) based on its class and class hierarchy. Some compositions of abilities are more difficult to describe in this manner due to the complexities of multiple inheritance, and the fact that C++ supports interface-only inheritance in a somewhat clumsy way (compared to java, etc), but it's there (and could be improved).</p>
  <p>And then templates came into play, along with the STL. The STL seems to take the classical OOP concepts and flush them down the drain, using templates instead.</p>
  <p>There should be a distinction between cases when templates are used to generalize types where the types themselves are irrelevant for the operation of the template (containers, for examples). Having a <code>vector&lt;int&gt;</code> makes perfect sense.</p>
  <p>However, in many other cases (iterators and algorithms), templated types are supposed to follow a &quot;concept&quot; (Input Iterator, Forward Iterator, etc...) where the actual details of the concept are defined entirely by the implementation of the template function/class, and not by the class of the type used with the template, which is a somewhat anti-usage of OOP.</p>
  <p>For example, you can tell the function:</p>
  <pre><code>void MyFunc(ForwardIterator&lt;...&gt; *I);
  </code></pre>
  <p><strong>Update:</strong> As it was unclear in the original question, ForwardIterator is ok to be templated itself to allow any ForwardIterator type. The contrary is having ForwardIterator as a concept.</p>
  <p>expects a Forward Iterator only by looking at its definition, where you'd need either to look at the implementation or the documentation for:</p>
  <pre><code>template &lt;typename Type&gt; void MyFunc(Type *I);
  </code></pre>
  <p>Two claims I can make in favor of using templates: 1. Compiled code can be made more efficient, by recompiling the template for each used type, instead of using dynamic dispatch (mostly via vtables). 2. And the fact that templates can be used with native types.</p>
  <p>However, I am looking for a more profound reason for abandoning classic OOP in favor of templating for the STL?</p>