Create custom data types

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Apr 29 16:22:43 PDT 2015


On 04/29/2015 04:16 PM, Ali Çehreli wrote:

>      ref CustomInteger opOpAssign(string op, T2)(T2 rhs)
>      {
>          static if (is (T2 == CustomInteger)) {
>              mixin("value_ " ~ op ~ "= rhs.value_;");
>              return this;
>
>          } else {
>              return this.opOpAssign!(op,
> CustomInteger)(CustomInteger(rhs));

Playing a little more, the following shorter equivalent of the last line 
works as well:

     return opOpAssign!op(CustomInteger(rhs));

Ali



More information about the Digitalmars-d-learn mailing list