title: How to convert iterators of different types
body: <p>I have a legacy function <code>Foo</code> which takes two iterators as input and I want to reuse it but should not change its interface (although I can change the type of iterators but can't make it template)<br>
  The problem is that I have iterators of different type and have to copy initial container to get iterators needed for <code>Foo</code> function<br>
  I was wondering is there any way to convert iterators of one type to iterators of another type?<br>
  I tried to use <code>boost::make_transform_iterator</code> but it won't compile saying iterators are of different types<br>
  Is it possible to uncomment and use the <code>option 2</code> (see code below)?</p>
  
  <pre><code>#include &lt;algorithm&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;iterator&gt;
  #include &lt;numeric&gt;
  
  #include &lt;boost/iterator/transform_iterator.hpp&gt;
  
  /* Method with fixed interface */
  void Foo(std::vector&lt;int&gt;::const_iterator beginIt, std::vector&lt;int&gt;::const_iterator endIt)
  {
      std::cout &lt;&lt; "ints:" &lt;&lt; std::endl;
      std::copy(beginIt, endIt, std::ostream_iterator&lt;int&gt;(std::cout, " "));
      std::cout &lt;&lt; std::endl;
  }
  
  int main()
  {
      const std::vector&lt;std::string&gt; strings { "2", "4", "6" };
      auto convertStringToInt = [](const std::string &amp; s) { return std::stoi(s); };
  
      // 1) Works, but creates another container with size of initial container
      std::vector&lt;int&gt; convertedInts;
      std::transform(strings.begin(), strings.end(), std::back_inserter(convertedInts), convertStringToInt);
      Foo(convertedInts.begin(), convertedInts.end());
  
      // 2) Doesn't compile, but operates only with iterators hence there's minimum overhead
      //auto beg = boost::make_transform_iterator(strings.begin(), convertStringToInt);
      //auto end = boost::make_transform_iterator(strings.end(), convertStringToInt);
      //Foo(beg, end);
  
      std::cout &lt;&lt; "strings:" &lt;&lt; std::endl;
      std::copy(strings.begin(), strings.end(), std::ostream_iterator&lt;std::string&gt;(std::cout, " "));
  }
  </code></pre>
  
  <p>The code can be compiled in online-compiler <a href="https://wandbox.org/" rel="nofollow noreferrer">wandbox</a> (it doesn't have a "share" feature)</p>
  
  <p><strong>Edit:</strong> <code>Foo</code> implements logic strictly specific for <code>int</code>'s so it's not possible to make it generic. But I have a container (of <code>std::string</code>'s as in example) elements of which I can convert to ints via non-capturing lambda.<br>
  It seems very odd that there no standard way to wrap one iterator into another :)</p>