Reset all Members of a Aggregate Instance

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at
Thu Dec 3 13:19:50 PST 2015

On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
> is there a generic way, perhaps through reflection, to reset 
> (inside f) all members of `c` to their default values?

You could always copy the init back over it. For a struct:

s = Struct.init;

for a class... well, the code is a lot uglier and liable to break 
if you don't have the static type right. Maybe better off 
wrapping the class members in a struct and doing it that way.

More information about the Digitalmars-d-learn mailing list