title: C++ "smart pointer" template that auto-converts to bare pointer but can't be explicitly deleted
body: <p>I am working in a very large legacy C++ code base which shall remain nameless.  Being a legacy code base, it passes raw pointers around all over the place.  But we are gradually trying to modernize it and so there are some smart pointer templates as well.  These smart pointers (unlike, say, Boost's scoped_ptr) have an implicit conversion to the raw pointer, so that you can pass one of them into a routine that takes a raw pointer without having to write <code>.get()</code>.  A big downside of this is that you can also accidentally use one in a <code>delete</code> statement, and then you have a double free bug, which can be a real pain to track down.</p>
  
  <p>Is there a way to modify the template so that it still has the implicit conversion to the raw pointer, but causes a compile error if used in a delete statement?  Like this:</p>
  
  <pre><code>#include &lt;my_scoped_ptr&gt;
  
  struct A {};
  extern void f(A*);
  
  struct B
  {
      scoped_ptr&lt;A&gt; a;
  
      B();
      ~B();
  };
  
  B::B()
      : a(new A)
  {
      f(a); // this should compile
  }
  
  B::~B()
  {
      delete a; // this should NOT compile
  }
  </code></pre>