<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Mon, May 2, 2016 at 1:20 PM Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Tony, thanks for writing this up!<br>
<br>
on Mon May 02 2016, Tony Allevato <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
<br>
> Other kinds of operators (prefix, postfix, assignment)<br>
><br>
> Static operator methods have the same signatures as their global counterparts.<br>
> So, for example, prefix and postfix operators as well as assignment operators<br>
> would be defined the way one would expect:<br>
><br>
> protocol SomeProtocol {<br>
> static func +=(lhs: inout Self, rhs: Self)<br>
> static prefix func ~(value: Self) -> Self<br>
><br>
> // This one is deprecated, of course, but used here just to serve as an<br>
> // example.<br>
> static postfix func ++(value: inout Self) -> Self<br>
> }<br>
><br>
> // Trampolines<br>
> func += <T: SomeProtocol>(lhs: inout T, rhs T) {<br>
> T.+=(&lhs, rhs)<br>
> }<br>
> prefix func ~ <T: SomeProtocol>(value: T) -> T {<br>
> return T.~(value)<br>
> }<br>
> postfix func ++ <T: SomeProtocol>(value: inout T) -> T {<br>
> return T.++(&value)<br>
> }<br>
<br>
How does one distinguish between calls to a static prefix operator and a<br>
static postfix operator with the same name?<br></blockquote><div><br></div><div>Ah, that's a tricky one that I don't have an immediate answer to, so I'm definitely open to creative thoughts here.</div><div><br></div><div>The first stab I would take at is, what if we included the token "prefix" or "suffix" before the operator name in the expression, like this?</div><div><br></div><div> return T.prefix ++(&value)</div><div> return T.postfix ++(&value)</div><div><br></div><div>But that could start to look like an invocation of "++" on a static property "T.prefix". I haven't dug into the parser to determine if that would even be feasible or not.</div><div><br></div></div></div>