Nostalgia I’m sure this can be improved up. Feel free to offer up suggestions: View the code on Gist. Share this:Click to share on Twitter (Opens in new window)Click to share on Facebook (Opens in new window) Related April 19, 2016 By erica Development, Swift 9 Comments Tweet this Post Default reflectionDefault reflection
9 Comments
Using defer
In your case:
postfix public func ++(inout x: Int) -> Int { defer { x += 1 }; return x }
Sold! Thanks
Weird, but interesting:
Your validator erased generic declaration.
i.e.:
postfix public func +++^T: IntegerArithmeticType^(inout x: T) -> T { defer { x += x/x }; return x }
x += x/x looks like a cool workaround, but what if x == 0?
How about making it:
postfix public func +++(inout x: T) -> T { defer { x = x.successor() }; return x }
How about performance? What ist the curent ++ postfix compared to such a generic function in Swift 3?
x += x/x โ as I noticed, it is just case not for using.
x.successor it’s good case of course ๐
damn parser… it was supposed to read:
postfix public func + + + etc.
!?$$&ยง*
It shall read IntegerType inside the angle brackets for the protocol requirements of the function declaration…