title: Question about functors
body: <p>The correct answer for this is D, but what I'm confused about is when exactly is the add operation in class dunno taking place? How are the numbers being added?</p>
  
  <blockquote>
    <p>Consider the following partial C++ code:</p>
  </blockquote>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  template&lt;class Iter, class Formatter&gt;
  void mystery(Iter front, Iter end, Formatter doSomething)
  {
      while (front != end)
      {
          doSomething(*front, *end):
          front++; end--;
      }
  }
  template &lt;class T&gt; class dunno
  {
  public:
      void operator()(T &amp; a, T &amp; b)
      {
          a = a + b;
      }
  }
  int main()
  {
      vector&lt;int&gt; v; ... // insert an odd number of elements into the vector
      vector&lt;int&gt;::iterator it1 - v.begin();
      vector&lt;int&gt;::iterator it2 - v.end();
      it2--;
      dunno&lt;int&gt; d;
      mystery&lt;vector&lt;int&gt;::iterator, dunno&lt;int&gt; &gt;(itl, it2, d);
      for (int i = 0; i &lt; v.size(); i++) cout &lt;&lt; v[i] &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <blockquote>
    <p>If you assume that all iterators are bidirectional and non-constant, which of the following statements is true?</p>
    
    <p>(a) This code does not compile because of a type mismatch in the mystery parameter list.</p>
    
    <p>(b) This code does not compile because of a syntax error in the template instantiation for mystery.</p>
    
    <p>(c) If the vector consists of the integers 1, 2, 3, 4, 5, 6, 7 in that order, with the first item on the left, then the output is 1, 2, 3, 4, 5, 6, 7. (i.e. the code dods not change the vector.)</p>
    
    <p>(d) If the vector consists of the integers 1, 2, 3, 4, 5, 6, 7 in that order, with the first item on the left, then the output is 8, 8, 8, 4, 5, 6, 7.</p>
    
    <p>(e) None of these options describes the behavior of this code.</p>
  </blockquote>