Strange behavior with opAssign and static if
Stanislav Blinov
stanislav.blinov at gmail.com
Sat Feb 8 05:27:42 PST 2014
__traits(allMembers) gives you *all* members, including methods
(even implicit).
As soon as you define opAssign for your Decimal, it gets defined
for OrderDb too, and then you try to assign to it :)
What you need is something like this:
void execute(T)(T struc){
Variant[] arr = new Variant[](2);
foreach(i, member; struc.tupleof) {
static if (isInstanceOf!(Decimal, typeof(member))){
// Store decimals as string
arr[i] = member.toString();
} else {
// Store other values with their types
arr[i] = member;
}
}
}
More information about the Digitalmars-d-learn
mailing list