
Martin <adrianm <at> touchdown.se> writes:
The only thing I am missing is a way to update the non-key elements in-place. Often my structures include subtables which means the copy can be expensive and I don't want to add member functions to update each member.
Currently I do
const_cast<std::vector<subtable>&>(itr->subtable).push_back(xxx);
It would be nice if there was a macro or template that could do it in a safe way, i.e. ensure index isn't changed.
nonkey(itr->subtable).push_back(xxx);
Well, you can build it yourself: template<typename T> T& deconst(const T& x) { return const_cast<T&>(x); } deconst(itr->subtable).push_back(xxx); But using this, you cannot really make the program enforce the immutability of keys, so you're basically on your being careful. No safe alternative that I know of by way of const_casting. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo