Fully transitive const is not necessary
Janice Caron
caron800 at googlemail.com
Tue Apr 1 07:57:50 PDT 2008
On 01/04/2008, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> Second, I'll show how logical const is ALREADY available with D's const,
> just in a less convenient form. Let's look at an invariant property that is
> not invariant:
>
> class X
> {
> private static int _x;
> invariant int x()
> {
> return _x++;
> }
> }
That does not break transitivity. You have misunderstood.
"invariant int x()" declares x() to be a function, within whose body
the variable "this" is invariant. X._x is a global variable, unrelated
to "this". Transitivity is not compromised.
> Notice that despite all efforts of the compiler to make sure invariant is
> transitive, it still cannot do any parallelizations or optimizations on the
> call to x. If it does not have the source code for x, it cannot be sure
> that x isn't doing something like the above.
However, in the future, you will be able to declare
class X
{
private static int _x;
invariant int x()
{
return _x++; /*ERROR*/
}
}
and suddenly - bingo - the offending line will not compile.
You gotta think ahead.
More information about the Digitalmars-d
mailing list