const debacle

Steven Schveighoffer schveiguy at yahoo.com
Wed Mar 26 11:34:41 PDT 2008


"Davidson Corry" wrote
>
> Does that make things clearer?
>

I think that we're all arguing the same point here :)

All of our suggestions accomplish the same thing, but I think yours is a tad 
less expressive than Janices and mine.

For example, if I want a mutable array of const characters, I use:

const(char)[]

I can pass this into a function no problem.

However, there is no way to put a trailing const in your scheme, unless you 
did something like:

(char const)[]

But I think this is really confusing to most people.  It's one of the things 
I didn't like about C++'s const, I never knew where to put the const because 
I could never remember which was which :)

The statement:

const(char)

is clear, it means whatever inside the parentheses is const.

Regarding using 'const' as the keyword for 'const during the function, but I 
can return the same type as you gave me', I think in order to use the 
parentheses scheme, we'd have to use another keyword.  But I think that the 
scheme should be just as expressive as const is now, which I don't see 
happening with the trailing const notation.

-Steve 





More information about the Digitalmars-d mailing list