Last active
June 14, 2022 16:30
-
-
Save schveiguy/2eea5d38c83fc76e52a4a2d7af03a289 to your computer and use it in GitHub Desktop.
D1 operator overloads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mixin template D1Ops() { | |
// binary operations | |
static foreach(op, d1; | |
["+" : "opAdd", "-" : "opSub", "*" : "opMul", "/" : "opDiv", | |
"%" : "opMod", "&" : "opAnd", "^" : "opXor", "|" : "opOr", | |
"<<" : "opShl", ">>" : "opShr", ">>>" : "opUShr", "~" : "opCat", | |
"in" : "opIn"]) { | |
static if(__traits(hasMember, typeof(this), d1)) | |
alias opBinary(string s : op) = mixin(d1); | |
// _r version | |
static if(__traits(hasMember, typeof(this), d1 ~ "_r")) | |
alias opBinaryRight(string s : op) = mixin(d1 ~ "_r"); | |
// assignment (everything except opIn) | |
static if(op != "in" && __traits(hasMember, typeof(this), d1 ~ "Assign")) | |
alias opOpAssign(string s : op) = mixin(d1 ~ "Assign"); | |
} | |
// unary operations | |
static foreach(op, d1; | |
["-" : "opNeg", "~" : "opCom", "++" : "opPostInc", | |
"--" : "opPostDec", "*" : "opStar"]) { | |
static if(__traits(hasMember, typeof(this), d1)) | |
alias opUnary(string s : op) = mixin(d1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment