The following line of code compiles just fine and behaves:
list<const int *> int_pointers; // (1)
The following two lines do not:
typedef int * IntPtr;
list<const IntPtr> int_pointers; // (2)
I get the exact same compile errors for
list<int * const> int_pointers; // (3)
I’m well aware that the last line is not legal since the elements of an STL container need to be assignable. Why is the compiler interpreting (2) to be the same as (3) ?
Short answer:
const (and volatile) should naturally appear after the type they qualify.
When you write it before, the compiler automatically rewrites it internally:
becomes
which is a pointer to a constant int. Lists of these will compile fine since the pointer itself is still assignable.