title: Deleting what unique_ptr points to
body: <p>I have a coding assignment and I need to free whatever memory I allocate, so I'm trying to delete all the semaphores that my unique_ptr's are pointing to. The unique_ptrs are all in a map. The code snippets:</p>
  
  <pre><code>static map&lt;string, unique_ptr&lt;semaphore&gt;&gt; locks;
  </code></pre>
  
  <p>This is where all the semaphores are created using "new":</p>
  
  <pre><code> 89         unique_ptr&lt;semaphore&gt;&amp; up = locks[article.title];
   90         if (up == nullptr) {
   91                 up.reset(new semaphore(6));
   92         }
  </code></pre>
  
  <p>Later, I try to delete the semaphores in the following code:</p>
  
  <pre><code>160         for (map&lt;string, unique_ptr&lt;semaphore&gt;&gt;::iterator it = locks.begin(); it != locks.end();
  161                 ++it) {
  162                 cout &lt;&lt; it-&gt;first &lt;&lt; endl;
  163                 delete it-&gt;second;
  164         }
  </code></pre>
  
  <p>And I get the compiler error: </p>
  
  <pre><code>news-aggregator.cc: In function âvoid processAllFeeds(const string&amp;)â:
  news-aggregator.cc:163:14: error: type âclass std::unique_ptr&lt;semaphore&gt;â argument given to âdeleteâ, expected pointer
  make: *** [news-aggregator.o] Error 1
  </code></pre>