| ▲ | vlovich123 a day ago | ||||||||||||||||
Then explain that const isn’t deep and a const container can end up mutating state? Pretending like c++ has a consistent philosophy is amusing and pretending this happened because of pedagogy is amusing. It happened because in c assignment is a copy and c++ inherited this regardless of how dumb it is as a default for containers. | |||||||||||||||||
| ▲ | kccqzy a day ago | parent [-] | ||||||||||||||||
In C++ regular types have the property that const is deep. If you have a const std::vector<int> the you can't modify any of the integers contained in this container. Naturally for flexibility reasons not all types are regular, pointers being the prominent exception, and things like std::string_view being modern examples of non-regular types. | |||||||||||||||||
| |||||||||||||||||