Reset all Members of a Aggregate Instance
Nordlöw via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Dec 3 13:30:07 PST 2015
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
> Something along
>
> foreach(ref member; __traits(allMembers, c))
> {
> member = typeof(member).init;
> }
This works for me:
void resetAllMembers(T)(T c)
if (is(T == class))
{
foreach (ref m; c.tupleof)
{
import std.traits : isMutable;
alias M = typeof(m);
static if (isMutable!M)
{
m = M.init;
}
}
}
More information about the Digitalmars-d-learn
mailing list