any news on const/invariant?

Janice Caron caron800 at googlemail.com
Mon Nov 26 22:47:09 PST 2007


On 11/26/07, Walter Bright <newshound1 at digitalmars.com> wrote:
> At the beginning will still work for function types. The at the end
> option is there for those who are building complex type declarations.

and

> No. "const char[] X;" and "const(char[]) X;" mean the same thing.

It seems to me that the following is still ambiguous:

    class A
    {
        int n;
    }

    class B
    {
        const A f() { /*...*/ }
    }

Does it mean (a)

    class B
    {
        const(A) f() { /*...*/ }
    }

or does it mean (b)

    class B
    {
        A f() const { /*...*/ }
    }

?

Also, is it still possible to write

    class C
    {
        int n;
        void f() invariant { /*...*/ };
    }

(I put the keyword at the end to avoid confusion. In D2.007, you'd
write "invariant" before "void"). My interpretation of the above code
is that f is being called with a hidden parameter "this" of type
"invariant(C)", which means that the function can never be called,
unless by an invariant instance of C (since nothing implicitly casts
to invariant). Have I got that right?



More information about the Digitalmars-d mailing list