restrict
is a C99 feature which is getting a lot of attention lately by allowing the compiler to perform "previously-fortran-only" optimizations to pointers. It's also the same keyword announced by Microsoft recently to be the underpinnings of the C++AMP specification.
Is that keyword actually in the FCD? If not, is there a specific reason it was omitted?
The only mention of
restrict
in the C++11 FDIS is on §17.2 [library.c]:So
restrict
is not in C++11.I will take a crack at "why not?"
restrict
is basically just an assertion that the compiler cannot verify. (Or more precisely, when the compiler can verify it, the assertion itself is not helpful.) This is just not the sort of thing that the C++ committee is going to like. C++ has always tended to assume "sufficiently smart compilers"; heck, look at the hideous performance of the most trivial C++ libraries before the compilers caught up.I also suspect the committee felt that defining
restrict
semantics precisely in the presence of all the other C++ features (references, rvalue references, blah blah blah) would be non-trivial.So, non-trivial to specify + "a sufficiently smart compiler doesn't need it" = NAK.
One argument is that C needs
restrict
more than C++, because many operations are done with pointers to primitive types and therefore C code has more aliasing problems than C++.The aliasing rules say that pointers to different types cannot alias, so if the parameters to a function are of different class types they just cannot overlap.
In C++ we also have the
valarray
family of classes that are supposed to handle arrays of primitive types that are not allowed to alias. Not that it is used much...Adding yet another way to resolve some aliasing problems, obviously didn't excite the committee enough.
Don't think it's in C++1x (unfortunately time has long run out for 0x...!) but at least msvc and g++ support it through
__restrict
and__restrict__
extensions. (I don't use gcc much, I think that's the correct extension).To work properly with C++ I feel that we would also need restricted references, not just pointers, maybe along the lines of my question C++ aliasing rules. Not sure if some of these considerations might be holding things up...
http://herbsutter.com/2012/05/03/reader-qa-what-about-vc-and-c99/