title: gsl::not_null<T*> vs. std::reference_wrapper<T> vs. T&
body: <p><a href="https://github.com/isocpp/CppCoreGuidelines">C++ Core Guidelines</a> has been presented recently (congrats!) and I am concerned about <code>gsl::not_null</code> type. As stated in <a href="https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-i12-declare-a-pointer-that-must-not-be-null-as-not_null">I.12: Declare a pointer that must not be null as <code>not_null</code></a>:</p>
  
  <blockquote>
    <p>To help avoid dereferencing nullptr errors. To improve performance by
    avoiding redundant checks for nullptr. </p>
    
    <p>... </p>
    
    <p>By stating the intent in
    source, implementers and tools can provide better diagnostics, such as
    finding some classes of errors through static analysis, and perform
    optimizations, such as removing branches and null tests.</p>
  </blockquote>
  
  <p>The intent is clear. However, we already have a language feature for that. Pointers that cannot be null are called references. And while references cannot be rebound once they are created, this problem is solved by <code>std::reference_wrapper</code>. </p>
  
  <p>The main difference between <code>gsl::not_null</code> and <code>std::reference_wrapper</code> I see in that the latter can be used only instead of pointers, while the former works on anything <code>nullptr</code>-assignable (quote from  <a href="https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-f17-use-a-not_nullt-to-indicate-that-null-is-not-a-valid-value">F.17: Use a not_null to indicate that "null" is not a valid value</a>):</p>
  
  <blockquote>
    <p><code>not_null</code> is not just for built-in pointers. It works for
    <code>array_view</code>, <code>string_view</code>, <code>unique_ptr</code>, <code>shared_ptr</code>, and other
    pointer-like types.</p>
  </blockquote>
  
  <p>I imagine the feature comparison table like the following:</p>
  
  <p><code>T&amp;</code>:</p>
  
  <ul>
  <li>Cannot store <code>nullptr</code>? - <strong>Yes</strong></li>
  <li>Rebindable? - <strong>No</strong></li>
  <li>Can be used instead of something other than pointers? - <strong>No</strong></li>
  </ul>
  
  <p><code>std::reference_wrapper&lt;T&gt;</code>:</p>
  
  <ul>
  <li>Cannot store <code>nullptr</code>? - <strong>Yes</strong></li>
  <li>Rebindable? - <strong>Yes</strong></li>
  <li>Can be used instead of something other than pointers? - <strong>No</strong></li>
  </ul>
  
  <p><code>gsl::not_null&lt;T*&gt;</code>:</p>
  
  <ul>
  <li>Cannot store <code>nullptr</code>? - <strong>Yes</strong></li>
  <li>Rebindable? - <strong>Yes</strong></li>
  <li>Can be used instead of something other than pointers? - <strong>Yes</strong></li>
  </ul>
  
  <p>Now here are the questions, finally:</p>
  
  <ol>
  <li>Is my understanding of differences between these concepts correct?</li>
  <li>Does that mean that <code>std::reference_wrapper</code> is now useless?</li>
  </ol>
  
  <p><strong>PS</strong> I created tags <code>cpp-core-guidelines</code> and <code>guideline-support-library</code> for this, I hope properly.</p>