opDispatch and operator overloads

Jonathan M Davis jmdavisProg at gmx.com
Mon May 20 10:19:41 PDT 2013


On Monday, May 20, 2013 17:15:32 John Colvin wrote:
> Also, would it be a good idea to have free functions of all the
> operators (opOpAssign etc...) for builtin types somewhere? It's
> occasionally useful in generic wrappers.

Why would this be useful? I think that it's just begging for trouble to be 
able to add stuff like "foo" + "bar" to the language via free functions. We 
don't _want_ that to be legal. That's why we have ~ in the first place. If you 
need to do something that you want to work with built-in types, and their 
operators don't do what you want, then just use a normal function rather than 
an operator. If you can't model your overloaded operator after what an 
operator does for the built-in types, it's arguably a bad choice to use an 
overloaded operator for that in the first place.

- Jonathan M Davis


More information about the Digitalmars-d mailing list