default implemented opAssign purity

Dan dbdavidson at yahoo.com
Sun Dec 2 07:50:28 PST 2012


On Sunday, 2 December 2012 at 14:13:34 UTC, Maxim Fomin wrote:
> On Sunday, 2 December 2012 at 13:07:42 UTC, Dan wrote:
>
> Default opAssign function is described here: 
> http://dlang.org/struct.html. It calls dtor and postblit (if 
> any) which are impure. Even if you mark them pure, you still 
> implicitly call opAssign which is not marked as pure. This can 
> be probably enhanced.
>

Exactly. I am suggesting that the default opAssign be marked 
pure, if in fact it is. I think it is. This way we would not need 
to implement an opAssign and duplicate code to just to get a pure 
version of opAssign.

>>
>> Also, in case the answer is no and default implemented 
>> opAssign must remain impure, is there a standard way, in a 
>> member function to do like:
>>
>
> Are you looking for this http://dpaste.dzfl.pl/7ee27db2 ?

I did not know you could call __postblit - that's cool. So, that 
is almost it. Ideally I want Don't Repeat Yourself (DRY). If I 
have implemented a postblit I don't want to duplicate my dups in 
an opAssign. I just want to invoke the postblit, which you have 
done, after a proper full blit of S. The only issue is how to 
actually blit other into this. Instead of manually "blitting" 
each field, which opens the door for bugs when new fields are 
added, something more like this, which unfortunately does not 
compile because of pure.

http://dpaste.dzfl.pl/d8937f43

Thanks
Dan



More information about the Digitalmars-d-learn mailing list