title: Why shouldn't we use pointer arithmetic with gsl::not_null?
body: <p>This is a contrived example, but consider the following:  </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "gsl.h"
  
  int main(){
  
    //object or array that I'd like to iterate over one byte at a time
    char array[] = {'a','b','c','d','e','f'};
  
    //create a C-like iterator
    char* it = &amp;array[0];
  
    //use pointer arithmetic to process
    std::cout &lt;&lt; *it &lt;&lt; std::endl; it++;
    std::cout &lt;&lt; *it &lt;&lt; std::endl; it++;
    std::cout &lt;&lt; *it &lt;&lt; std::endl; it++;
  }
  </code></pre>
  
  <p>For safety, I'd like to tag the pointer with <code>not_null</code>.<br>
  <strong>However, this fails to compile.</strong>   </p>
  
  <pre><code>#include "gsl.h"
  #include &lt;iostream&gt;
  
  int main(){
  
    //object or array that I'd like to iterate over one byte at a time
    char array[] = {'a','b','c','d','e','f'};
  
    //create a C-like iterator
    gsl::not_null&lt;char*&gt; it = &amp;array[0];
  
    //use pointer arithmetic to process
    std::cout &lt;&lt; *it &lt;&lt; std::endl; it++;
    std::cout &lt;&lt; *it &lt;&lt; std::endl; it++;
    std::cout &lt;&lt; *it &lt;&lt; std::endl; it++;
  }
  </code></pre>
  
  <p><em>An except from <code>not_null</code>'s class :</em></p>
  
  <pre><code>// unwanted operators...pointers only point to single objects!
  // TODO ensure all arithmetic ops on this type are unavailable
  not_null&lt;T&gt;&amp; operator++() = delete;
  not_null&lt;T&gt;&amp; operator--() = delete;
  not_null&lt;T&gt; operator++(int) = delete;
  not_null&lt;T&gt; operator--(int) = delete;
  not_null&lt;T&gt;&amp; operator+(size_t) = delete;
  not_null&lt;T&gt;&amp; operator+=(size_t) = delete;
  not_null&lt;T&gt;&amp; operator-(size_t) = delete;
  not_null&lt;T&gt;&amp; operator-=(size_t) = delete;
  </code></pre>
  
  <p>I'm confused as to why they've done this.<br>
  Why can't I have a pointer that changes its value?  </p>
  
  <p>Especially when it is easy to get around:   </p>
  
  <pre><code>it = &amp;array[0];
  it = static_cast&lt;char*&gt;(it)+1;
  </code></pre>
  
  <p>Am I missing the point of <code>not_null</code>?<br>
  The <a href="http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Ri-nullptr" rel="nofollow">C++ Guidelines</a> don't cover why something like this would be a bad use case.</p>