How to copy object of class A to another object of class B?

Baz via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 28 06:51:27 PST 2015


On Wednesday, 28 January 2015 at 14:35:58 UTC, zhmt wrote:
> Anybody help?

__Traits functions are evaluated at compile time so it's not as 
simple.
The best you can do is to generate a string to mixin based on the 
aggragate members. here i have an example of how you can iterate 
through the members: 
https://github.com/BBasile/Iz/blob/master/import/iz/traits.d#L18

Writing an opAssign() operator will be as fast, you just need to 
remember to keep it in sync with the classe members.

You could also generate the struct programmatically, based on the 
classes declaration.


More information about the Digitalmars-d-learn mailing list