Doc Comments /
Const
Difference (last change) (no other diffs, normal page display)
Added: 12a13,33
Do you mean this example? [[quote]int const *const *const *p; // C++ ] The const keyword binds to the thing to its immediate left. In pseudo code, that's like: [[quote](((int const) *const) *const) *p; // pseudo C++ ] A pointer to a const pointer to a const pointer to a const int. == Const Correctness == My first thought on D Programming Language was its lack of const correctness. After a discussion with a co-worker, we both realized that D Programming Language supports immutability though an interface. So you could have an interface that is just accessors, hence immutable, and the derived implementation which has mutators and accessors. The benefits of C++ const correctness, without the co-mingling of two interfaces in one class -- the const marked methods in C++ being one interface which can be used in a const or non-const context, and the other methods which can only be used in a non-const context. Apple uses this pattern extensively in their Cocoa frameworks. For example, NSAttributedString? and NSMutableAttributedString?. |
Here A Const, There A Const
Messages
Add your comments here...
Constness in D (first example in section)
I think there is some trouble with the first C++ example after the header "Constness in D". There is const pointer to const pointer to const pointer to not-const int.
Do you mean this example?
![]() |
|
The const keyword binds to the thing to its immediate left. In pseudo code, that's like:
![]() |
|
A pointer to a const pointer to a const pointer to a const int.
Const Correctness
My first thought on D Programming Language was its lack of const correctness. After a discussion with a co-worker, we both realized that D Programming Language supports immutability though an interface. So you could have an interface that is just accessors, hence immutable, and the derived implementation which has mutators and accessors.
The benefits of C++ const correctness, without the co-mingling of two interfaces in one class -- the const marked methods in C++ being one interface which can be used in a const or non-const context, and the other methods which can only be used in a non-const context.
Apple uses this pattern extensively in their Cocoa frameworks. For example, NSAttributedString? and NSMutableAttributedString?.
Links
