tail const

vincent picaud vincent.picaud at laposte.net
Wed Dec 1 05:52:31 PST 2010


Reading back my first post I realized that there are a lot of confusions... please ignore it and consider the corrected version here:

At least one facet of the problem is a "syntax" problem. Doing a parallel with C++
and concerning pointers there are 4 possible variants:

// C++
1/ int *p;
2/ const int *p;
3/ int *const  p;
4/ const int *const p;

In D, if I try the summarize the situation, we have (right?) :
1/ int *p;
2/ const(int)* p;
3/ ? <- not allowed because of const transitivity property
4/ const(int*) p;

Now concerning D objects, there are some kind of "implicit pointers" (with
reference counting) with no direct equivalent in C++ (and hence this problem does not occur in C++).
IMHO the syntaxic problem is the consequence of a missing "place holder" for the two "const" attributes (because there is no more "*" to play with in the declaration).

Perhaps one idea is to make "_" plays the role of this missing place holder. To
make things clear, for a class A the D syntax would be:

1/ __ = nothing: A p ( no change )
2/ const_(A) p; (mimic "const int *p;")
3/ _const(A) p; (would mimic "int *const p;" but anyway _forbiden_ in D due to const transitivity)
4/ const(A)  p; (no change)

To summarize there would be just one keyword to add in D : "const_". This attribute would have sense only for Objects (the same logic would also hold for "immutable_"). To my IMHO the syntax const_ is easy to unerstand, because "_" clearly shows the place holder position and its missing "const"
(remembering C++)

... hope there is not more error in this post...sic


More information about the Digitalmars-d mailing list