title: Is there a way to let template function automatically deduce an iterator's underlying data type?
body: <p>I have a function where I need an iterator's underlying data type as return type, like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;iterator&gt;
  
  template&lt;class T, class ForwardIterator&gt;
  std::vector&lt;T&gt; get_odd(ForwardIterator data_begin, ForwardIterator data_end)
  {
      std::vector&lt;T&gt; ret;
      std::copy_if(data_begin, data_end, std::back_inserter(ret), [](int x) { return x % 2; });
      return ret;
  }
  
  int main()
  {
      std::vector&lt;int&gt; vi { 1, 2, 3, 4, 5 };
      for (auto i : get_odd&lt;int&gt;(vi.begin(), vi.end()))
          std::cout &lt;&lt; i &lt;&lt; ", ";
      std::cout &lt;&lt; std::endl;
  
      std::vector&lt;unsigned int&gt; vui{ 9UL, 8UL, 7UL, 6UL, 5UL };
      // Note the 'char' I provided to the function, this will print weird chars
      for (auto i : get_odd&lt;char&gt;(vui.begin(), vui.end()))
          std::cout &lt;&lt; i &lt;&lt; ", ";
      std::cout &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>In the main(), I have to explicitly provide data type 'int' or 'char' to the get_odd function, is there a way to find out iterator's underlying data type, and let template automatically deduct the correct data type?</p>