const challenge

Janice Caron caron800 at googlemail.com
Fri Feb 1 00:03:25 PST 2008


On Feb 1, 2008 3:15 AM, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> How is this not what you want?

In D1, it's /exactly/ what you want.

But if you've ever tried to port Tango code to D2 (I have) 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. To get it to compile, you more or less have to take const
out right the way up the chain to the higher level API, and ultimately
end up not being able to pass strings (which are invariant) to
functions to which you would natually want to pass them. It's the
whole "rippling up" effect.

>From memory, I believe my workaround was to keep those nifty functions
exactly as is, but hide some casting in upper layers of the API. Of
course, for that not to result in undefined behavior, you have to
understand /exactly/ what is being modified and when, and that's where
the brain starts to hurt.



More information about the Digitalmars-d mailing list