I can declare foo(const T& var) so that I know var won’t be changed.
Equivalent format for pointer would be foo(const T* var)?
In the past I tried those, errors related to iterator/const_iterator irritated me and I just tended to use (T* var) without considering constness.
Are there a good doc for declaring function that enforces contents pointed by a pointer won’t change’?
What you have is already a pointer that prohibits the pointee’s contents from changing. You can see this by using the “read backwards” rule:
Reading backwards:
This is different from
Which reads:
The difference here is that the constant is
var, not theT; that means you can change theTby dereferencingvarbut you cannot change whatvarpoints to.And of course you can have both of the above at the same time: