vector<const string>
and
const vector<string>
and
const vector<const string>
Let's say I have a vector of strings of the name of each month declared and defined in the global scope. The vector is to be used by a lot of parts of the application. I want it the values to be constant, what kind of const should I use?
vector<const string>: Cannot change the values of the elements of this vector after they've been added. EDIT: This may fail to compile on a pre-C++11 compiler.
const vector<string>: Cannot change anything about the vector.
The type of the element of a sequence container must be at least MoveAssignable, several operation require that it also must be CopyAssignable
Therefore, std::vector<const std::string> is badly formed.
The logical state of a sequence container includes the state of the elements which makes up the sequence; so in a const std::vector<std::string>, the container itself (vector) as well as the elements it contains (strings) are immutable.