title: Best way to create a fake smart pointer when you need one but only have a reference?
body: <p>What's the best way to fake a shared pointer for situations like below where you know it's ok?</p>
  
  <pre><code>#include &lt;memory&gt;
  
  struct Target {
      bool ok() { return true; }
  };
  
  struct Monitor {
      // Take a shared pointer as we will be using it later
      Monitor(std::shared_ptr&lt;Target&gt; target)
          : target(target)
      { }
  
      bool check() {
          // Use the shared pointer we grabbed before
          return this-&gt;target-&gt;ok();
      }
  
      std::shared_ptr&lt;Target&gt; target;
  };
  
  // This function does not take a shared pointer because it does not
  // hold on to the object after returning.
  bool checkTargetOnce(Target&amp; t)
  {
      // We have to pass a shared_ptr to Monitor() because it wants to
      // keep a copy after the constructor returns.  But we know in this
      // case the Monitor instance won't be used after we return, so we
      // don't need a shared_ptr here - but we have to supply one anyway.
  
      Monitor m(t); // What should be put here?
  
      return m.check();
  }
  
  int main(void)
  {
      Target t;
      checkTargetOnce(t);
      return 0;
  }
  </code></pre>