The standard library vector prevents us from constructing a vector of consts. My question is why? I read the answers on apparently similar questions to mine and I'm not really convinced. So let's dig into some examples and see what happens:
vector<const int>
: there is no harm in relocatingconst int
if we need to- Const flat objects (objects with no pointers to resources): those objects can be moved easily without any problem
- Const Objects using shared smart pointers are easily copy constructible: in this case relocation is possible
The only apparent case (to me) that needs the object to be non constant is when the objects contains raw pointers to other resources (and in modern C++, those tend to be rare)
For me it is like a vendor of a TV set preventing me to switch it on (by some mechanism) between 4am and 5am just because some random channel plays loud music at that time and his TV can't support that level of sound!! where a simple warning could be sufficient