title: Static Smart Pointers - Yay or Nay?
body: <p>Say I have an object-- we'll called it Obj-- and I want it contain a static pointer to an instance of it's own type. Ex:</p>
  
  <pre><code>class Obj{
      static auto get_active_obj() -&gt; const Obj*;
      auto make_active_obj() -&gt; void;
  
  private:
      static const Obj* active;
  };
  </code></pre>
  
  <p>Now, would it be good practice to use a smart pointer, specifically a shared_ptr, in this scenario? The idea behind using a shared_ptr here is that when the user queries the object with get_active_obj, I can just return a weak_ptr to the active object, and the user could query this to check if the active object has changed/is still valid. Now, question is, is this the most optimal (or even a viable) solution? Ex:</p>
  
  <pre><code>class Obj{
      static auto get_active_obj() -&gt; std::weak_ptr&lt;const Obj&gt;;
      auto make_active_obj() -&gt; void;
  
  private:
      //another concern with this is that I have to provide a "no-OP" 
      //deleter to prevent a segfault when the shared_ptr tries to delete a static    
      //pointer.
      static std::shared_ptr&lt;const Obj&gt; active;
  };
  
  int main(){
      Obj o;
      o.make_active_obj();
  
      auto active = Obj::get_active_obj();
      if(active.expired()){ //is it still active?
          auto active_obj = active.lock();
          //do stuff
      }
  
  }
  </code></pre>
  
  <p>Conceptual implementation of make_active_obj():</p>
  
  <pre><code>auto make_active_obj()const -&gt; void {
      active.reset(this);
  }
  </code></pre>
  
  <p>destructor:</p>
  
  <pre><code>~Obj(){
      if(this == active.get())
          active.reset();
  }
  </code></pre>