title: apply transformation to vector with index using template function
body: <p>I am trying to apply a transformation on a vector while also adding the index in the transformation function. I am using the following transformation function <code>transformWithIndex</code>. If I remove <code>idx</code> from <code>result.push_back(itransformationFunction(idx, element));</code> it works correctly. </p>
  
  <blockquote>
    <p>I understood that I have an extra argument. But I don't understand how
    to modify the transformation function in order to handle the IDX.</p>
  </blockquote>
  
  <hr>
  
  <pre><code>// Example program That can be tested
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  template &lt;typename Range, class TransformationFunction&gt;
  inline std::vector&lt;typename std::result_of&lt;TransformationFunction(typename Range::value_type)&gt;::type&gt;
  transformWithIndex(const Range &amp;iRange, const TransformationFunction &amp;itransformationFunction) {
    std::vector&lt;typename std::result_of&lt;TransformationFunction(typename Range::value_type)&gt;::type&gt; result;
    int                                                                                            idx = 0;
    for (auto &amp;&amp;element : iRange) {
      result.push_back(itransformationFunction(idx, element));
      idx++;
    }
    return result;
  }
  
  int main()
  {
     std::vector&lt;int&gt; source = {1, 2, 3};
     std::vector&lt;int&gt; result = transformWithIndex(source, [](int i) { return ++i; });
  
     return 0;
  }
  </code></pre>
  
  <hr>
  
  <p>The errors are the following:</p>
  
  <pre><code>&gt;  In instantiation of 'std::vector&lt;typename
  &gt; std::result_of&lt;TransformationFunction(typename
  &gt; Range::value_type)&gt;::type&gt; transformWithIndex(const Range&amp;, const
  &gt; TransformationFunction&amp;) [with Range = std::vector&lt;int&gt;;
  &gt; TransformationFunction = main()::&lt;lambda(int)&gt;; typename
  &gt; std::result_of&lt;TransformationFunction(typename
  &gt; Range::value_type)&gt;::type = int]': 21:82:   required from here 12:58:
  &gt; error: no match for call to '(const main()::&lt;lambda(int)&gt;) (int&amp;,
  &gt; const int&amp;)' 21:58: note: candidates are: 12:58: note: int (*)(int)
  &gt; &lt;conversion&gt; 12:58: note:   candidate expects 2 arguments, 3 provided
  &gt; 21:65: note: main()::&lt;lambda(int)&gt; 21:65: note:   candidate expects 1
  &gt; argument, 2 provided
  </code></pre>