Steven Schveighoffer wrote:
On Sat, 28 Nov 2009 18:36:07 -0500, Walter Bright <newshou...@digitalmars.com> wrote:

And here it is (called opDispatch, Michel Fortin's suggestion):

http://www.dsource.org/projects/dmd/changeset?new=trunk%2f...@268&old=trunk%2f...@267

I have a few questions:

1. How should the compiler restrict opDispatch's string argument? i.e. if I implement opDispatch, I'm normally expecting the string to be a symbol, but one can directly call opDispatch with any string (I can see clever usages which compile but for instance circumvent const or something), forcing me to always constrain the string argument, i.e. always have isValidSymbol(s) in my constraints. Should the compiler restrict the string to always being a valid symbol name (or operator, see question 2)?

Where in doubt, acquire more power :o). I'd say no checks; let user code do that or deal with those cases.

2. Can we cover templated operators with opDispatch? I can envision something like this:

opDispatch(string s)(int rhs) if(s == "+") {...}

How do you mean that?


Andrei

Reply via email to