Why can't I put structures with const values โโinside a container like std::vector ? (I understand the technical reason the compiler is reporting, I'm just not sure if the compiler / collection should do it this way)
For example, something very simple:
struct sample { int const a; }; std::vector<sample> v; v.push_back( sample{12} );
This gives an error (at least in GCC) about using remote operator= . But I do not understand why it should use operator= . When creating this vector, you do not need to use the copy operator. If he does not use contour-copying in place of a new one, which is quite acceptable. For example, everything is in order:
sample a; new (&a) sample{12};
Calling the sample destructor is also great. That is, there are enough allowed operations on this type to build a vector, but I can not do this. I thought C ++ 11 with rvalue and move semantics might also help here, but maybe I'm wrong.
What part of the standard specifically prohibits this or is it really a compiler error (unlikely)?
source share