title: How to erase elements from boost::ptr_vector
body: <p>So I'm trying to get rid of my std::vector's by using boost::ptr_vector. Now I'm trying to remove an element from one, and have the removed element deleted as well. The most obvious thing to me was to do:</p>
  
  <pre><code>class A
  { int m; };
  
  boost::ptr_vector&lt;A&gt; vec;
  A* a = new A;
  vec.push_back(a);
  vec.erase(a);
  </code></pre>
  
  <p>But this won't even compile (see below for the full error message). I've tried the erase/remove idiom like I would on a std::vector but all the algorithms of boost::ptr_vector turn out to be slightly different from those in std::vector.</p>
  
  <p>So my questions:</p>
  
  <ul>
  <li>How do I remove a pointer from a ptr_vector?</li>
  <li>Do I still need to manually delete() that element that I removed?</li>
  </ul>
  
  <p>Compiler error:</p>
  
  <pre><code>1&gt;------ Build started: Project: ptr_vector_test, Configuration: Debug Win32 ------
  1&gt;Compiling...
  1&gt;ptr_vector_test.cpp
  1&gt;c:\users\rvanhout\svn\trunk\thirdparty\boost\range\const_iterator.hpp(37) : error C2825: 'C': must be a class or namespace when followed by '::'
  1&gt;        c:\users\rvanhout\svn\trunk\thirdparty\boost\mpl\eval_if.hpp(63) : see reference to class template instantiation 'boost::range_const_iterator&lt;C&gt;' being compiled
  1&gt;        with
  1&gt;        [
  1&gt;            C=A *
  1&gt;        ]
  1&gt;        c:\users\rvanhout\svn\trunk\thirdparty\boost\range\iterator.hpp(63) : see reference to class template instantiation 'boost::mpl::eval_if_c&lt;C,F1,F2&gt;' being compiled
  1&gt;        with
  1&gt;        [
  1&gt;            C=true,
  1&gt;            F1=boost::range_const_iterator&lt;A *&gt;,
  1&gt;            F2=boost::range_mutable_iterator&lt;A *const &gt;
  1&gt;        ]
  1&gt;        c:\users\rvanhout\svn\trunk\thirdparty\boost\ptr_container\detail\reversible_ptr_container.hpp(506) : see reference to class template instantiation 'boost::range_iterator&lt;C&gt;' being compiled
  1&gt;        with
  1&gt;        [
  1&gt;            C=A *const 
  1&gt;        ]
  1&gt;        c:\tmp\ptr_vector_test\ptr_vector_test.cpp(21) : see reference to function template instantiation 'boost::void_ptr_iterator&lt;VoidIter,T&gt; boost::ptr_container_detail::reversible_ptr_container&lt;Config,CloneAllocator&gt;::erase&lt;A*&gt;(const Range &amp;)' being compiled
  1&gt;        with
  1&gt;        [
  1&gt;            VoidIter=std::_Vector_iterator&lt;void *,std::allocator&lt;void *&gt;&gt;,
  1&gt;            T=A,
  1&gt;            Config=boost::ptr_container_detail::sequence_config&lt;A,std::vector&lt;void *,std::allocator&lt;void *&gt;&gt;&gt;,
  1&gt;            CloneAllocator=boost::heap_clone_allocator,
  1&gt;            Range=A *
  1&gt;        ]
  1&gt;c:\users\rvanhout\svn\trunk\thirdparty\boost\range\const_iterator.hpp(37) : error C2039: 'const_iterator' : is not a member of '`global namespace''
  1&gt;c:\users\rvanhout\svn\trunk\thirdparty\boost\range\const_iterator.hpp(37) : error C2146: syntax error : missing ';' before identifier 'type'
  1&gt;c:\users\rvanhout\svn\trunk\thirdparty\boost\range\const_iterator.hpp(37) : error C2208: 'boost::type' : no members defined using this type
  1&gt;c:\users\rvanhout\svn\trunk\thirdparty\boost\range\const_iterator.hpp(37) : fatal error C1903: unable to recover from previous error(s); stopping compilation
  1&gt;Build log was saved at "file://c:\tmp\ptr_vector_test\Debug\BuildLog.htm"
  1&gt;ptr_vector_test - 5 error(s), 0 warning(s)
  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  </code></pre>