title: Why STL requires a temporary iterator variable to compile this?
body: <p>Here is a very straightforward piece of code:</p>
  
  <pre><code>#include &lt;vector&gt;
  
  int main() {
  
      std::vector&lt;int&gt; myVec(5);
      std::vector&lt;int&gt;::const_iterator first = myVec.begin();
      std::vector&lt;int&gt;::const_iterator last = myVec.begin() + 3;
      std::vector&lt;int&gt; newVec1(first, last);
      std::vector&lt;int&gt; newVec2(myVec.begin(), last);
  
      return 0;
  }
  </code></pre>
  
  <p>Line declaring <code>newVec1</code> compiles.</p>
  
  <p>Line declaring <code>newVec2</code> fails with following error:</p>
  
  <pre><code>prog.cpp: In function 'int main()':
  prog.cpp:11:49: error: no matching function for call to 'std::vector&lt;int&gt;::vector(std::vector&lt;int&gt;::iterator, std::vector&lt;int&gt;::const_iterator&amp;)'
       std::vector&lt;int&gt; newVec2(myVec.begin(), last);
                                                   ^
  prog.cpp:11:49: note: candidates are:
  In file included from /usr/include/c++/4.9/vector:64:0,
                   from prog.cpp:3:
  /usr/include/c++/4.9/bits/stl_vector.h:401:9: note: template&lt;class _InputIterator, class&gt; std::vector&lt;_Tp, _Alloc&gt;::vector(_InputIterator, _InputIterator, const allocator_type&amp;)
           vector(_InputIterator __first, _InputIterator __last,
           ^
  /usr/include/c++/4.9/bits/stl_vector.h:401:9: note:   template argument deduction/substitution failed:
  prog.cpp:11:49: note:   deduced conflicting types for parameter '_InputIterator' ('__gnu_cxx::__normal_iterator&lt;int*, std::vector&lt;int&gt; &gt;' and '__gnu_cxx::__normal_iterator&lt;const int*, std::vector&lt;int&gt; &gt;')
       std::vector&lt;int&gt; newVec2(myVec.begin(), last);
                                                   ^
  In file included from /usr/include/c++/4.9/vector:64:0,
                   from prog.cpp:3:
  /usr/include/c++/4.9/bits/stl_vector.h:373:7: note: std::vector&lt;_Tp, _Alloc&gt;::vector(std::initializer_list&lt;_Tp&gt;, const allocator_type&amp;) [with _Tp = int; _Alloc = std::allocator&lt;int&gt;; std::vector&lt;_Tp, _Alloc&gt;::allocator_type = std::allocator&lt;int&gt;]
         vector(initializer_list&lt;value_type&gt; __l,
         ^
  /usr/include/c++/4.9/bits/stl_vector.h:373:7: note:   no known conversion for argument 1 from 'std::vector&lt;int&gt;::iterator {aka __gnu_cxx::__normal_iterator&lt;int*, std::vector&lt;int&gt; &gt;}' to 'std::initializer_list&lt;int&gt;'
  /usr/include/c++/4.9/bits/stl_vector.h:348:7: note: std::vector&lt;_Tp, _Alloc&gt;::vector(std::vector&lt;_Tp, _Alloc&gt;&amp;&amp;, const allocator_type&amp;) [with _Tp = int; _Alloc = std::allocator&lt;int&gt;; std::vector&lt;_Tp, _Alloc&gt;::allocator_type = std::allocator&lt;int&gt;]
         vector(vector&amp;&amp; __rv, const allocator_type&amp; __m)
         ^
  /usr/include/c++/4.9/bits/stl_vector.h:348:7: note:   no known conversion for argument 1 from 'std::vector&lt;int&gt;::iterator {aka __gnu_cxx::__normal_iterator&lt;int*, std::vector&lt;int&gt; &gt;}' to 'std::vector&lt;int&gt;&amp;&amp;'
  /usr/include/c++/4.9/bits/stl_vector.h:339:7: note: std::vector&lt;_Tp, _Alloc&gt;::vector(const std::vector&lt;_Tp, _Alloc&gt;&amp;, const allocator_type&amp;) [with _Tp = int; _Alloc = std::allocator&lt;int&gt;; std::vector&lt;_Tp, _Alloc&gt;::allocator_type = std::allocator&lt;int&gt;]
         vector(const vector&amp; __x, const allocator_type&amp; __a)
         ^
  /usr/include/c++/4.9/bits/stl_vector.h:339:7: note:   no known conversion for argument 1 from 'std::vector&lt;int&gt;::iterator {aka __gnu_cxx::__normal_iterator&lt;int*, std::vector&lt;int&gt; &gt;}' to 'const std::vector&lt;int&gt;&amp;'
  /usr/include/c++/4.9/bits/stl_vector.h:335:7: note: std::vector&lt;_Tp, _Alloc&gt;::vector(std::vector&lt;_Tp, _Alloc&gt;&amp;&amp;) [with _Tp = int; _Alloc = std::allocator&lt;int&gt;]
         vector(vector&amp;&amp; __x) noexcept
         ^
  /usr/include/c++/4.9/bits/stl_vector.h:335:7: note:   candidate expects 1 argument, 2 provided
  /usr/include/c++/4.9/bits/stl_vector.h:318:7: note: std::vector&lt;_Tp, _Alloc&gt;::vector(const std::vector&lt;_Tp, _Alloc&gt;&amp;) [with _Tp = int; _Alloc = std::allocator&lt;int&gt;]
         vector(const vector&amp; __x)
         ^
  /usr/include/c++/4.9/bits/stl_vector.h:318:7: note:   candidate expects 1 argument, 2 provided
  /usr/include/c++/4.9/bits/stl_vector.h:289:7: note: std::vector&lt;_Tp, _Alloc&gt;::vector(std::vector&lt;_Tp, _Alloc&gt;::size_type, const value_type&amp;, const allocator_type&amp;) [with _Tp = int; _Alloc = std::allocator&lt;int&gt;; std::vector&lt;_Tp, _Alloc&gt;::size_type = unsigned int; std::vector&lt;_Tp, _Alloc&gt;::value_type = int; std::vector&lt;_Tp, _Alloc&gt;::allocator_type = std::allocator&lt;int&gt;]
         vector(size_type __n, const value_type&amp; __value,
         ^
  /usr/include/c++/4.9/bits/stl_vector.h:289:7: note:   no known conversion for argument 1 from 'std::vector&lt;int&gt;::iterator {aka __gnu_cxx::__normal_iterator&lt;int*, std::vector&lt;int&gt; &gt;}' to 'std::vector&lt;int&gt;::size_type {aka unsigned int}'
  /usr/include/c++/4.9/bits/stl_vector.h:277:7: note: std::vector&lt;_Tp, _Alloc&gt;::vector(std::vector&lt;_Tp, _Alloc&gt;::size_type, const allocator_type&amp;) [with _Tp = int; _Alloc = std::allocator&lt;int&gt;; std::vector&lt;_Tp, _Alloc&gt;::size_type = unsigned int; std::vector&lt;_Tp, _Alloc&gt;::allocator_type = std::allocator&lt;int&gt;]
         vector(size_type __n, const allocator_type&amp; __a = allocator_type())
         ^
  /usr/include/c++/4.9/bits/stl_vector.h:277:7: note:   no known conversion for argument 1 from 'std::vector&lt;int&gt;::iterator {aka __gnu_cxx::__normal_iterator&lt;int*, std::vector&lt;int&gt; &gt;}' to 'std::vector&lt;int&gt;::size_type {aka unsigned int}'
  /usr/include/c++/4.9/bits/stl_vector.h:264:7: note: std::vector&lt;_Tp, _Alloc&gt;::vector(const allocator_type&amp;) [with _Tp = int; _Alloc = std::allocator&lt;int&gt;; std::vector&lt;_Tp, _Alloc&gt;::allocator_type = std::allocator&lt;int&gt;]
         vector(const allocator_type&amp; __a) _GLIBCXX_NOEXCEPT
         ^
  /usr/include/c++/4.9/bits/stl_vector.h:264:7: note:   candidate expects 1 argument, 2 provided
  /usr/include/c++/4.9/bits/stl_vector.h:253:7: note: std::vector&lt;_Tp, _Alloc&gt;::vector() [with _Tp = int; _Alloc = std::allocator&lt;int&gt;]
         vector()
         ^
  /usr/include/c++/4.9/bits/stl_vector.h:253:7: note:   candidate expects 0 arguments, 2 provided
  </code></pre>
  
  <p>Both g++ and Visual Studio fail to compile this, any idea why?
  <code>myVec.begin()</code> is the same as <code>first</code>...</p>