<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">+1</div><div class=""><br class=""></div><div class="">Not symmetrical by default, but able to add an attribute/keyword to auto-generate a default implementation which swaps the lhs & rhs.</div><div class=""><blockquote type="cite" class=""><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">Hi, list!
I’m thinking about proposal that would add a possibility to save some time on creating symmetrical binary operators.
The latest code example from my math lib:
@inline(__always)
public static func *(lhs: Angle, rhs: Float) -> Angle {
return Angle(lhs.degrees * rhs)
}
@inline(__always)
public static func *(lhs: Float, rhs: Angle) -> Angle {
return Angle(rhs.degrees * lhs)
}
The API of Angle doesn’t really matter here, what’s important is that I have to write another operator to make it symmetrical. Not so hard: 3 lines of code. It can even refer to original implementation, instead of duplicating the logic. But I think it would be nice to have something like symmetrical keyword, just like we have associativity and precedence.
I also bet that all operators should be asymmetrical by default.
Any thoughts?</pre></blockquote><div class=""><br class=""></div></div></body></html>