On Sunday, 29 December 2013 at 18:27:16 UTC, Benjamin Thaut wrote:
No unfortunately not. You could solve the issue by adding another level of indirection. So always allocate the additional indirection, then its save to copy it, and then you can lazy instaniate the actual instance when needed and all copies of your wrapper will see the instance.

Kind Regards
Benjamin Thaut

Even with that, you'd still have to make sure the newly inserted indirection gets initialized *prior* to the copy, so it's back to square one...

Am 29.12.2013 17:22, schrieb Ritu:
Ok, I will give you some background of what I am trying to do.

I have a struct that wraps a class object and lazily initializes it. Now in case the struct instance is passed as an argument to a function and it has not been initialized yet, the default copy constructor and the postblit do not offer a possibility to initialize the class object
before copying.

Any possibility of *preblit* kind functionality?

Regards
- Ritu

Nope. What you are asking for is basically a default constructor, which D does not provide. Workarounds include the "static opCall" pattern, as well as the "function builder" pattern (eg: "MyStruct myStruct(Args args)")

Reply via email to