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 __restrict
. This seems to be the most-standard-extension, so I'll use restrict
and __restrict
interchangeably.
restrict
is a C99 keyword, but nevertheless compilers have defined important uses for it in C++.
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 restrict
keyword mean?"
Qualifying
this
(restrict a method):void Foo::method(int*__restrict a) __restrict { /*...*/ }
Restrict a reference:
int&__restrict x = /*...*/;
Restrict inside a template:
std::vector<float*__restrict> x;
Restrict a member/field. This technically also applies to C's
struct
, but it comes up as an issue in C++ more often than it does in C:class Foo final { public: int*__restrict field; };