After reading this post I tried this
#include <iostream>
#include <vector>
int main()
{
const int x = 5;
// x = 200; Not possible, of course.
std::vector<const int> xVector = { 5 };
xVector[0] = 200;
std::cout << xVector[0]; // 200, no surprise.
}
This compiles in Visual Studio 2017. But is this behaviour undefined as in UB?
Bonus questions: What are the technical reasons that a std::vector<const int>
isn't just a vector of un-modifiable int
s?