Bypassing the postblit?

Benjamin Thaut code at benjamin-thaut.de
Sun Dec 29 10:27:18 PST 2013


Am 29.12.2013 17:22, schrieb Ritu:
>
>> No. In D, struct are freely copied or moved depending on whether the
>> source is an lvalue or an rvalue. What is possible is to define the
>> post-blit function to work on the already-blitted destination object.
>>
>> For example, if you don't want the source and the destination share a
>> member slice, the destination object's post-blit can make a copy.
>
> 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

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


More information about the Digitalmars-d mailing list