Hi everyone,
in my recent shift from arrays and pointers to vectors and iterators, I have begun to wonder whether I can restrict pointer aliasing of vector iterators. Take this for example:
Well the iterators, which are essentially pointers, could be aliased as they could dereference to the same value. But since this is not happening I'd like to tell the compiler about it, much like you do with the restrict command for pointer declarations...
C++ simply has no concept of restricted pointers or any other extensions of the strict aliasing rule, except that the data in std::valarrays are never aliased.
A few C++ compilers transplanted restricted pointers from C, but it remains a compiler-specific language extension, and it's up to the compiler vendor to consider extending it to std::vector's, std::string's, and std::array's iterators (no other iterators would work even in principle, by the way). In practice, compiler vendors seem to put more effort in automatic vectorization of the loops found in the standard library algorithms instead. So far, to the best of my knowledge, the answer is "no".
C++ has strict aliasing so if you have a pointer or iterator to an int the compiler can assume the data will not be the same as the data pointed to by a float pointer or other types. There are some exception to this rule. void*, char* and unsigned char* (perhaps some more) can point to data of any type.