title: Why can I not move unique_ptr from a set to a function argument using an iterator?
body: <p>I have a <code>set</code> of <code>unique_ptr</code> instances and want to pass all of them as an argument to a function. Example demonstrated by below code.</p>
  
  <pre><code>#include &lt;memory&gt;
  #include &lt;set&gt;
  #include &lt;vector&gt;
  
  using std::set;
  using std::unique_ptr;
  using std::vector;
  
  void doStuff(unique_ptr&lt;int&gt; ptr)
  {
    // doing stuff...
  }
  
  int main()
  {
    vector&lt;unique_ptr&lt;int&gt;&gt; ptrVector;
    set&lt;unique_ptr&lt;int&gt;&gt; ptrSet;
  
    for (auto cur = ptrVector.begin(); cur != ptrVector.end(); cur++)
    {
      doStuff(std::move(*cur));
    }
  
    for (auto cur = ptrSet.begin(); cur != ptrSet.end(); cur++)
    {
      doStuff(std::move(*cur));
    }
  
    return 0;
  }
  </code></pre>
  
  <p>This results in the following compiler error (GCC 4.8.1):</p>
  
  <pre>uptrfncall.cpp: In function ‘int main()’:
  uptrfncall.cpp:27:25: error: use of deleted function ‘std::unique_ptr::unique_ptr(const std::unique_ptr&) [with _Tp = int; _Dp = std::default_delete]’
    doStuff(std::move(*cur)); // line 25, compiler error
                           ^
  In file included from /usr/include/c++/4.8/memory:81:0,
                   from uptrfncall.cpp:1:
  /usr/include/c++/4.8/bits/unique_ptr.h:273:7: error: declared here
         unique_ptr(const unique_ptr&) = delete;
         ^
  uptrfncall.cpp:9:10: error:   initializing argument 1 of ‘void doStuff(std::unique_ptr)’
       void doStuff(unique_ptr ptr)
            ^</pre>
  
  <p>Note that it works flawlessly for the <code>vector</code> but not for the <code>set</code>. As the <code>set</code> is not <code>const</code>, the <code>begin()</code> call should not return a <code>const_iterator</code> so it should be possible to move the values when dereferencing the iterator. Why does this not compile?</p>