tail const

vincent picaud vincent.picaud at laposte.net
Wed Dec 1 04:13:07 PST 2010


Hello community, that is my first post here.
My background is more than 10 years of C++ and to be positive I would like to say
that there are a lot of things I love in D ( perhaps the object of a new thread :O) ).

> Speaking about D mistakes Steve spoke about missing tail const.
> I was thinking about this, and I fully agree that it is a hole.

I fully agree with that and IMHO I think D must supports this natively.

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/ int *const p;
3/ const int * p;
4/ const int *const p;

In D, if I try the summarize the situation, we have :
1/ int *p;
2/ const(int)* p;
3/ forbiden due to the "const transitivity" philosophy
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 "int *const p;")
3/ const_(A) p; (mimic "const int *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"

I hope this suggestion is not too naive and can help the debate...


More information about the Digitalmars-d mailing list