Reset all Members of a Aggregate Instance
Nordlöw via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Dec 3 13:09:30 PST 2015
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
> Given
>
> class C
> {
> // lots of members
> }
>
> and a function
>
> f(C c)
> {
> }
>
> is there a generic way, perhaps through reflection, to reset
> (inside f) all members of `c` to their default values?
> Something along
>
> foreach(ref member; __traits(allMembers, c))
> {
> member = typeof(member).init;
> }
Back in 2007 it didn't seem to exist a standard way of doing this:
http://forum.dlang.org/post/fbs9eg$721$1@digitalmars.com
Is tupleof the best contender?
More information about the Digitalmars-d-learn
mailing list