title: Method operating on container: hardcode the container type, or use generic template iterators?
body: <p>I have code where, conceptually, my input is some container of <code>Foo</code> objects. The code "processes" these objects one by one, and the desired result is to fill up a container of <code>FooProduct</code> result objects. </p>
  
  <p>I only need a single pass through the input container. The "processing" is stateful (this isn't an <code>std::transform()</code>) and the number of result objects is independent of the number of input objects.</p>
  
  <p>Offhand, I could see two obvious ways to define the API here.</p>
  
  <p>The easiest way to do this is to hardcode a specific type of container. For example, I could decide I'm expecting <code>vector</code> parameters, e.g.:</p>
  
  <pre><code>void ProcessContainerOfFoos(const std::vector&lt;Foo&gt;&amp; in, std::vector&lt;FooProduct&gt;&amp;out);
  </code></pre>
  
  <p>But, I don't really have any reason to limit client code to a particular type of container. Instead of constraining the parameter types specifically to <code>vector</code>, I could make the method generic and use iterators as template parameters:</p>
  
  <pre><code>/**
   * @tparam Foo_InputIterator_T An input iterator giving objects of type Foo.
   * @tparam FooProduct_OutputIterator_T An output iterator writing objects 
   *                                     of type FooProduct.
   */
  template&lt;typename Foo_InputIterator_T, typename FooProduct_OutputIterator_T &gt;
  void ProcessContainerOfFoos(Foo_InputIterator_T first, Foo_InputIterator_T last,
                       FooProduct_OutputIterator_T out);
  </code></pre>
  
  <p>I'm debating between these two formulations. </p>
  
  <h2>Considerations</h2>
  
  <p>To me, the first code seems to me to be "easier" and the second seems "more correct":</p>
  
  <ul>
  <li>Non-template types make the signature clearer; I don't need to explain in the documentation what types to use and what the constraints on the template parameter are.</li>
  <li>Without templates I can hide the implementation in the .cpp file; with templates I'll need to expose the implementation in a header file, forcing client code to include anything I need for the actual processing logic.</li>
  <li>The templated version feels like it expresses my intention more clearly, because I'd rather be indifferent to what container type is used.</li>
  <li>The templated version is more flexible and testable - for example, in my code I might be using some custom data structure <code>MySuperEfficientVector</code> , but I'd still be able to test <code>MyFooProcessor</code> without any dependency on the custom class.</li>
  </ul>
  
  <p>Beyond subjective choice given these considerations, <strong>is there a major reason to choose one of these over the other?</strong> Likewise, <strong>is there a better way to construct this API which I'm missing?</strong></p>