On Tuesday, 31 May 2016 at 06:40:31 UTC, Era Scarecrow wrote:
On Tuesday, 31 May 2016 at 05:31:59 UTC, chmike wrote:
My conclusion is that rebindable is not a satisfying solution
to have mutable references to immutable objects.
I don't understand the rationale of these immutable
references. It is too constraining.
I still don't know why you're trying to use immutable. In the
other thread you have listed you are trying to make a global
singleton? You needed it mutable but marked immutable (for...
some reason?) but all the methods won't change the contents or
spirit of the object.
I need to wrap my head around what you're trying to do before
i can suggest anything else. Although making all members
private and all functions as const would give you a
mutable/unchanging object...
The code I gave are just examples.
The reason I used immutable is because I have two types of
objects.
I have many Info objects (~150) which are all singletons.
These Info objects have a reference to a Category objects which
is also a singleton.
I can have mutable singleton objects. I have a public interface
that doesn't allow to modify the object. This is not the problem.
The problem is that I would like that all these objects are
instantiated at compile time. This is to keep the start of the
program fast.
There is no problem to instantiate the Category object at compile
time. The problem is to instantiate the different Info objects at
compile time that have a reference to the Category object. Ctfe
doesn't work when a global variable is referenced.
I noticed that it worked when the Category is declared immutable.
I can add a reference to that Category singleton instance to the
new call of the Info objects.
So the goal is to create and interconnect multiple objects at
compile time. Ideally I would need to store a reference to each
of the Info objects in an associative array so that I can
retrieve a reference to it with some key.