default implemented opAssign purity
Dan
dbdavidson at yahoo.com
Sun Dec 2 13:47:25 PST 2012
On Sunday, 2 December 2012 at 19:12:46 UTC, Ali Çehreli wrote:
> On 12/02/2012 07:50 AM, Dan wrote:
> I was going to ask "Is __postblit a part of the language spec"
> but then I found TypeInfo.postblit:
>
> http://dlang.org/phobos/object.html#postblit
>
> I hoped the following might work:
>
> typeid(this).postblit(&this);
>
> But no, it is not pure:
>
> Error: pure function 'opAssign' cannot call impure function
> 'postblit'
I see that for this postblit:
this(this) { c = c.dup; }
But if I do it like this:
this(this) pure { c = c.dup; }
it seems to honor it (i.e. no compile error):
http://dpaste.dzfl.pl/00674ebb
For me the problem is opAssign - I don't want to write it to get
pure. I will if I have to - but if I do I don't want to be duping
all fields. If I have to do that I'll give up on pure. The reason
I'm in this rabbit hole is trying to get a const static and
assigning it from a pure function seemed to be the trick to allow
it at compile time.
Thanks,
Dan
More information about the Digitalmars-d-learn
mailing list