const challenge

Steven Schveighoffer schveiguy at yahoo.com
Fri Feb 1 04:24:07 PST 2008


"Janice Caron" wrote
> On Feb 1, 2008 3:15 AM, Steven Schveighoffer wrote:
>> How is this not what you want?
>
> In D1, it's /exactly/ what you want.

D1 does not have this type of function signature possible, I was talking 
about D2.

>
> But if you've ever tried to port Tango code to D2 (I have)

I have.  In fact, Frank Benoit and I successfully produced a tango tree that 
worked with D 2.007.

> then this
> is the point at which constancy gets in the way. Assuming one wants
> const correctness at higher levels, the compiler baulks because at
> some point you end up trying to pass const data to a non-const
> function.

We did not have that happen to us.  We did not have a single place where we 
had to cast away const.  Of course, we did not produce a fully const tango, 
but that was mostly because there were still some bugs with const that made 
it impossible to be const-correct in Tango.  Namely, that you could not 
overload a const function with a non-const function, and that you could 
override a const function with a non const function  )(there were probably 
others, but those stand out in my mind).  I'm not sure if these have been 
fixed in the latest DMD, but I think your arguments are anecdotal without an 
anecdote.

I believe it is possible with the proposed const scheme to have const 
arguments and const functions and be fully const-correct.  Invariant 
functions and invariant args, that's a different story.  Because you cannot 
yet implicitly cast a mutable return value to an invariant, even though 
technically it is, code is going to look ugly.  either you have wrapper 
functions for everything which do the cast, or you have to cast in your 
code.  This is where your unique idea comes in handy, and that's really the 
only place I support it (as the return value of a function).

-Steve 





More information about the Digitalmars-d mailing list