Fully transitive const is not necessary
guslay
guslay at gmail.com
Wed Apr 2 11:23:18 PDT 2008
Janice Caron Wrote:
> Logical const in mutually incompatible with transitive const. No
> object can be simultaneously both fully transitive and have reachable
> mutable fields. It's just impossible. (Here I define "reachable" as
> meaning "
>
What's logical const anyway? The bitwise/mutable definition is skewed in the context of D.
Saying that is logical const :
class C
{
mutable int a;
int f() const { ++a; }
}
while this isn't:
class C
{
static int a;
int f() const { ++a; }
}
is kind of a reach.
Proposition are dismissed because they exhibit logical const behavior, like it's some kind of disease. Those propositions merely point out that D const is just logical const anyway (even if it pretends not to be).
At the function level, const/invariant is nothing more that an abstraction. It just means that the method will run in some "protected mode". Some data reachable trough const function are immutable, some are not. Even with the transitive rule. Even without mutable members.
At the data level, const/invariant is enforced (bitwise const).
The problem with C++ const is not that it is logical. The difference is that C++ const is basically just an annotation, while D has some potential for enforcement (data are bitwise const).
D
- Functions => logical const.
- Data => bitwise const.
C++
- Functions => logical const.
- Data => const just a annotation.
More information about the Digitalmars-d
mailing list