Last update October 22, 2007

Doc Comments /

Here A Const, There A Const


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?

int const *const *const *p; // C++

The const keyword binds to the thing to its immediate left. In pseudo code, that's like:

(((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?.


Corresponding page in the D Specification

FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: October 22, 2007 17:14 (diff))