Immutable member functions on mutable objects

Simen kjaeraas simen.kjaras at gmail.com
Sun Nov 29 13:22:04 PST 2009


On Sun, 29 Nov 2009 19:15:19 +0100, Tomek Sowiñski <just at ask.me> wrote:

>> A is not implicitly castable to immutable(A), only to const(A).
>
> I think it is. This compiles:
> immutable a = A(3.4);
> But only because it's copied.

Not quite. If you try

immutable(A) a;
a = A(3.4);

you should find that it does not compile. Only because there must be
a way to initialize immutable objects does your example compile.

> BTW, the future optimization options are about removing locks or  
> something more?

Removing locks, yes. Also, pure functions take only immutable
(or copied) parameters and may be optimized out if the same function
is called several times with the same parameters. There may be other
optimizations I am not aware of or do not remember OTOH.

-- 
Simen


More information about the Digitalmars-d-learn mailing list