title: C++ restrict Semantics
body: <p>I'm in the process of updating performance critical libraries to use restrict, as implemented in C++11 by g++ and MSVC with the keyword <code>__restrict</code>.  This seems to be the most-standard-extension, so I'll use <code>restrict</code> and <code>__restrict</code> interchangeably.</p>
  
  <p><code>restrict</code> is a C99 keyword, but nevertheless compilers have defined important uses for it in C++.</p>
  
  <p>This post intends to be a "question" asking about what each C++-specific use is and what it means, followed by a CW answer answering it.  Feel free to add/check/edit.  So: "Help!  What do these C++ uses of the <code>restrict</code> keyword mean?"</p>
  
  <ol>
  <li><p>Qualifying <code>this</code> (restrict a method):</p>
  
  <pre><code>void Foo::method(int*__restrict a) __restrict { /*...*/ }
  </code></pre></li>
  <li><p>Restrict a reference:</p>
  
  <pre><code>int&amp;__restrict x = /*...*/;
  </code></pre></li>
  <li><p>Restrict inside a template:</p>
  
  <pre><code>std::vector&lt;float*__restrict&gt; x;
  </code></pre></li>
  <li><p>Restrict a member/field.  This technically also applies to C's <code>struct</code>,  but it comes up as an issue in C++ more often than it does in C:</p>
  
  <pre><code>class Foo final { public: int*__restrict field; };
  </code></pre></li>
  </ol>