digitalmars.D - unary operator overloading syntax
- =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench robertmuench.de> Jun 12 2010
- Lutger <lutger.blijdestijn gmail.com> Jun 12 2010
- =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench robertmuench.de> Jun 12 2010
- Lutger <lutger.blijdestijn gmail.com> Jun 12 2010
- Trass3r <un known.com> Jun 13 2010
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:(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.
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=="-") { ... }
Jun 12 2010
void* opUnary("*")() {...
Gotta be opUnary(string op : "*")() {
Jun 13 2010









Lutger <lutger.blijdestijn gmail.com> 