title: std::shared_ptr which is empty but not null
body: <p><a href="http://www.cplusplus.com/reference/memory/shared_ptr/" rel="nofollow noreferrer">http://www.cplusplus.com/reference/memory/shared_ptr/</a> says</p>
  
  <blockquote>
    <p>A shared_ptr that does not own any pointer is called an empty shared_ptr. A shared_ptr that points to no object is called a null shared_ptr and shall not be dereferenced. Notice though that an empty shared_ptr is not necessarily a null shared_ptr, and a null shared_ptr is not necessarily an empty shared_ptr.</p>
  </blockquote>
  
  <p>Am I able to create an empty std::shared_ptr, i.e. one which does not own anything but which is not null, i.e. contains payload?</p>
  
  <p>The usecase is to marry "legacy" code with the modern pointers: Given that <code>foo</code>'s call syntax is not to be changed,</p>
  
  <pre><code>void foo(const MyClass* p) {
     if (p == nullptr) {
         auto defaultObject = std::make_shared&lt;MyClass&gt;("some", "parameters");
         defaultObject-&gt;doSomething();
         ...
         defaultObject-&gt;doSomethingElse();
         // The default object must be destroyed again
     } else {
         p-&gt;doSomething();
         ...
         p-&gt;doSomethingElse();
         // p must not be destroyed, its memory is managed somewhere else
     }
  }
  </code></pre>
  
  <p>is there an implementation for <code>doNotOwnButStillPointTo()</code> which allows this:</p>
  
  <pre><code>void foo(const MyClass* p) {
      std::shared_ptr&lt;MyClass&gt; wrapper;
      if (p == nullptr) {
          // Create a default object
          wrapper = std::make_shared&lt;MyClass&gt;("some", "parameters");
      } else {
          wrapper = doNotOwnButStillPointTo(p);
      }
  
      wrapper-&gt;doSomething();
      ...
      wrapper-&gt;doSomethingElse();
      // p mus not be destroyed, the default object (if created) shall be
  }
  </code></pre>
  
  <p>Or, to not fall for the <a href="https://meta.stackexchange.com/a/66378/262836">XY-Problem</a>, is there a different smart pointer available or none at all?</p>
  
  <ul>
  <li>However, I want to add, that the line <code>std::make_shared&lt;MyClass&gt;("some", "parameters")</code> is actually a call to a more complex function which creates a shared_ptr. I'd like to retain this function and use its result</li>
  </ul>