Last active
April 20, 2016 21:57
-
-
Save erica/5afb13c72ec372a09042bb29dbbd77a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
ericasadun.com | |
Sometimes letting go doesn't mean saying goodbye | |
*/ | |
prefix operator ++ {} | |
// @discardableResult | |
prefix public func ++(inout x: Int) -> Int { x += 1; return x } | |
// @discardableResult | |
prefix public func ++(inout x: UInt) -> UInt { x += 1; return x } | |
postfix operator ++ {} | |
// @discardableResult | |
postfix public func ++(inout x: Int) -> Int { defer {x += 1}; return x } | |
// @discardableResult | |
postfix public func ++(inout x: UInt) -> UInt { defer {x += 1}; return x } | |
prefix operator -- {} | |
// @discardableResult | |
prefix public func --(inout x: Int) -> Int { x -= 1; return x } | |
// @discardableResult | |
prefix public func --(inout x: UInt) -> UInt { x -= 1; return x } | |
postfix operator -- {} | |
// @discardableResult | |
postfix public func --(inout x: Int) -> Int { defer {x -= 1}; return x } | |
// @discardableResult | |
postfix public func --(inout x: UInt) -> UInt { defer {x -= 1}; return x } | |
// Alternatively, deriving 1 | |
// via Pilipenko Dima http://github.com/dimpiax | |
postfix operator +++ {} | |
postfix public func +++<T: IntegerArithmeticType>(inout x: T) -> T { defer { x += x/x }; return x } | |
prefix operator +++ {} | |
prefix public func +++<T: IntegerArithmeticType>(inout x: T) -> T { x += x/x; return x } | |
// CGFloat versions apparently need separate implementations | |
//prefix public func +++(inout x: CGFloat) -> CGFloat { defer { x += 1 }; return x } | |
//prefix public func +++(inout x: CGFloat) -> CGFloat { x += 1; return x } | |
// via "torquato" | |
postfix operator ++++ {} | |
postfix public func ++++<T: BidirectionalIndexType>(inout x: T) -> T { defer { x = x.successor() }; return x } | |
prefix operator ++++ {} | |
prefix public func ++++<T: BidirectionalIndexType>(inout x: T) -> T { x = x.successor(); return x } | |
postfix operator ---- {} | |
postfix public func ----<T: BidirectionalIndexType>(inout x: T) -> T { defer { x = x.predecessor() }; return x } | |
prefix operator ---- {} | |
prefix public func ----<T: BidirectionalIndexType>(inout x: T) -> T { x = x.predecessor(); return x } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment