How do you properly use immutable on class members?

Fruitful Approach fruitfulapproach at gmail.com
Tue Mar 29 17:58:11 UTC 2022


I have immutable members:

`immutable immutable(Prop)[] axioms` which I can't initialize 
with Prop[], so I call this "immutable-poisoning" of the rest of 
my code.  Can you provide a 10 line example of how to best work 
with immutable types, specifically immutable members, together 
with ctor, and accessor methods?

Also do I need to do `immutable immutable(Prop)[]` - that seems 
kind of wordy, especially when I have to duplicate that typing 
elsewhere.  I could use an alias called `Axioms` I guess.

Every time I use const or immutable in C++ or D I end up failing 
with too many weird compilation errors, so I end up undoing all 
the places I inserted it.  Should I just _not use_ immutable or 
const except for on `const` method decoration where applicable?

There's no good tutorial on a realistic immutable example AFAIK.


More information about the Digitalmars-d-learn mailing list