Fully transitive const is not necessary
Steven Schveighoffer
schveiguy at yahoo.com
Thu Apr 3 12:42:00 PDT 2008
"Janice Caron" wrote
> On 03/04/2008, Steven Schveighoffer wrote:
>> I'm not introducing a 'new' language feature. Logical const is already
>> available through workarounds. I'm suggesting we make it easier to
>> express
>> logical const than by the hackish workarounds I've posted.
>
> Presumably though, what you call a "hackish workaround" is exactly
> what the compiler would have to implement for you if you got what you
> want. That is,
>
> class C
> {
> mutable M m;
> }
>
> would just be syntactic sugar for
>
> class C
> {
> private static M[const(C)] __cache;
> /* and appropriate functions to make it work */
> }
>
> Maybe it's better to have all that explicit, rather than hidden, so
> that it becomes obvious there's a price to pay, and that the lookup
> time for an AA had better be insignificant compared to the cost of
> computing an M or it's not worth it.
This isn't what I'm requesting. I'm requesting that
class C
{
mutable M m;
}
Mean exactly what it says, that there is a piece of data stored with the
class that is always mutable (to get nitpicky, I don't like the keyword
mutable, as it implies that everything reachable through m is mutable, which
it may not be). I'm asking for the compiler to treat it as not part of the
object state, *as if* it were a variable outside the class, in terms of
const. Think of it as an extra argument to all member functions that is not
colored with the constancy of the member function.
There is no need for the compiler to implement my hack, I can do that easily
enough with a mixin :) If that was the problem, I would have never started
this thread.
-Steve
More information about the Digitalmars-d
mailing list