2 ms·
> D's const is also transitive, meaning that if something is const, then everything it contains or refers to is also const. If D code has the equivalent of cons
by abacate 9y ago
> D's const is also transitive, meaning that if something is const, then everything it contains or refers to is also const. If D code has the equivalent of const vector<T*>, then not only is the container treated as const, but the elements are as well.
And that is not necessarily what the programmer wants.
There are a number of uses for a constant vector and non-const objects. Adding "const" in front of "T" should make everything constant, but just assuming everything is constant does not allow one to have non-const objects.
Unless there is a way to override this, it looks like a severe limitation in the language.
- deleted 9y ago[deleted]