title: How to force only smart pointers instance for a class?
body: <p>I've been working on a way to prevent user of using a class without smart pointers. Thus, forcing them to have the object being heap allocated and managed by smart pointers.
  In order to get such a result, I've tried the following :
  </p>
  
  <pre><code>#include &lt;memory&gt;
  class A
  {
  private :
      ~A {}
      // To force use of A only with std::unique_ptr
      friend std::default_delete&lt;A&gt;;
  };
  </code></pre>
  
  <p>This work pretty well if you only want your class users being capable of manipulating instance of your class through <code>std::unique_ptr</code>. But it doesn't work for <code>std::shared_ptr</code>. So I'd like to know if you had any ideas to get such a behavior. The only solution that I've found is doing the following (using <code>friend std::allocator_traits&lt;A&gt;;</code> was unsufficient) :
  </p>
  
  <pre><code>#include &lt;memory&gt;
  class A
  {
  private :
      ~A {}
      // For std::shared_ptr use with g++
      friend __gnu_cxx::new_allocator&lt;A&gt;;
  };
  </code></pre>
  
  <p>But this solution is not portable. Maybe I'm doing it the wrong way.</p>