is my code to get CTFE instantiated object valid D ?

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat May 28 01:34:17 PDT 2016


On Saturday, 28 May 2016 at 05:30:26 UTC, chmike wrote:

> What is the difference between a const and immutable object ? 
> would a const object be allowed to modify itself by using a 
> hash table or caching results inside ?

The difference lies in the guarantees of const and immutable.

Foo f = new Foo;
const(F) cf = f;

The above is legal. The single instance can modify itself in 
methods called via f, but not those called via cf. So the answer 
to the second question is no, not directly.

Foo f = new Foo;
immutable(f) if = f;

This will not compile. The compiler expects that any reference 
assigned to if will not be modified anywhere in the program, 
ever. It does not have the same expectation of const references.

> Is a static const Category c variable a TLS variable ?

Yes. All variables are TLS unless explicitly marked with 
__gshared or shared.


More information about the Digitalmars-d-learn mailing list