4 ms·
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 th
by vlovich123 1y 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 1y agoIn 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.
- vlovich123 1y agoI feel like you could benefit from watching Scott Meyers about the silliness in C++ if you feel like there’s a consistent and logical feel to the language. A lot of this is c++-isms masquerading sensible ideas through official terms (regular and non-regular types)
- kccqzy 1y agoOh I certainly do not feel like there's consistency in the language. The C++ language is such that everyone picks a subset that makes sense to them and is relatively consistent. Regular and non-regular types are however a basic idea that transcends languages. I can write a snippet in Python too: import copy from some.random.module.on.pypi import foo a = foo() b = copy.copy(a) assert a == b If that assertion fails it implies the type isn't regular.
- vlovich123 1y agoCan you point me to terminology other than the c++ spec (preferably literature) that defines regular types? I can only find references to this concept in c++ land.
- kccqzy 1y agoI think this terminology was originally invented by Stepanov. And he used C++ to explain the concept. That's why you can only find references to this concept in C++ land. https://stepanovpapers.com/DeSt98.pdf https://stepanovpapers.com/DeSt98.pdf is probably the original paper. Others have over time refined and redefined the idea of a regular type.