title: How to return smart pointers (shared_ptr), by reference or by value?
body: <p>Let's say I have a class with a method that returns a <code>shared_ptr</code>.</p>
  
  <p>What are the possible benefits and drawbacks of returning it by reference or by value?</p>
  
  <p>Two possible clues:</p>
  
  <ul>
  <li><strong>Early object destruction.</strong> If I return the <code>shared_ptr</code> by (const) reference, the reference counter is not incremented, so I incur the risk of having the object deleted when it goes out of scope in another context (e.g. another thread). Is this correct? What if the environment is single-threaded, can this situation happen as well?</li>
  <li><strong>Cost.</strong> Pass-by-value is certainly not free. Is it worth avoiding it whenever possible?</li>
  </ul>
  
  <p>Thanks everybody.</p>