Strange behavior with opAssign and static if

Andre andre at s-e-a-p.de
Sat Feb 8 05:37:18 PST 2014


Thanks a lot!
This works great.

Am 08.02.2014 14:27, schrieb Stanislav Blinov:
> __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