title: weak_ptr - Dereferencing - Throw if expired
body: <p>Dereferencing a <code>weak_ptr</code> does not automatically check whether the pointer has expired. Why is it designed this way ?</p>
  
  <p>I would like to safely dereference weak pointers without first having to check them using <code>expired()</code> and throw an exception if they are null.</p>
  
  <p>Would this be a good practice and what would be a right way to do that ? Should I overload <code>*</code> and <code>-&gt;</code> operators so that they perform this check first ? Should I write a free function ?</p>
  
  <p>Something like :</p>
  
  <pre><code>template&lt; typename T &gt;
  weak_ptr&lt; T &gt; &amp; check( weak_ptr&lt; T &gt; &amp; p )
  {
      if( p.expired() )
          throw logic_error( "Trying to dereference a null pointer." );
      return p;
  }
  </code></pre>
  
  <p>And then :</p>
  
  <pre><code>weak_ptr&lt; int &gt; pi;
  int i = *check( pi );
  </code></pre>
  
  <p>Thank you.</p>