digitalmars.D - unary operator overloading syntax
- =?iso-8859-1?Q?Robert_M._M=FCnch?= (10/10) Jun 12 2010 Hi, why does this work:
- Lutger (3/16) Jun 12 2010 (string s) is a (template) parameter to opUnary, containing the operator...
- =?iso-8859-1?Q?Robert_M._M=FCnch?= (6/8) Jun 12 2010 You mean, "only the first syntax is valid" because the second version
- Lutger (8/16) Jun 12 2010 Yes, sorry, that was a mistake. Note you can also do things like this wi...
- Trass3r (1/2) Jun 13 2010 Gotta be opUnary(string op : "*")() {
Hi, why does this work: void* opUnary(string s)() if (s == "*"){... but this not: void* opUnary("*")() {... If the first syntax is the only possible one, can I have several opUnary entries per struct/class or do I have to build a big switch inside the code section and use "s" to dispatch to correct handler? -- Robert M. Münch http://www.robertmuench.de
Jun 12 2010
Robert M. Münch wrote:Hi, why does this work: void* opUnary(string s)() if (s == "*"){... but this not: void* opUnary("*")() {... If the first syntax is the only possible one, can I have several opUnary entries per struct/class or do I have to build a big switch inside the code section and use "s" to dispatch to correct handler?(string s) is a (template) parameter to opUnary, containing the operator to be matched, so only the latter is valid syntax. You can have multiple opUnary templates distinguished by constraints, or a switch, or a combination thereof.
Jun 12 2010
On 2010-06-12 12:20:14 +0200, Lutger said:(string s) is a (template) parameter to opUnary, containing the operator to be matched, so only the latter is valid syntax.You mean, "only the first syntax is valid" because the second version (latter) doesn't compile for me. -- Robert M. Münch http://www.robertmuench.de
Jun 12 2010
Robert M. Münch wrote:On 2010-06-12 12:20:14 +0200, Lutger said:Yes, sorry, that was a mistake. Note you can also do things like this with constraints: void* opUnary(string s)() if (s == "*") { ... } void* opUnary(string s)() if (s=="++" || s=="--" || s=="+" || s=="-") { ... }(string s) is a (template) parameter to opUnary, containing the operator to be matched, so only the latter is valid syntax.You mean, "only the first syntax is valid" because the second version (latter) doesn't compile for me.
Jun 12 2010
void* opUnary("*")() {...Gotta be opUnary(string op : "*")() {
Jun 13 2010