Skip to content

Instantly share code, notes, and snippets.

@oozoofrog
Created July 18, 2016 07:05
Show Gist options
  • Save oozoofrog/1825aa36dcb4d27988afeb76937f4ed5 to your computer and use it in GitHub Desktop.
Save oozoofrog/1825aa36dcb4d27988afeb76937f4ed5 to your computer and use it in GitHub Desktop.
Custom operator for OptionSetType ref: http://qiita.com/DevLife1978/items/c66abd557e8b465728d3
func -=<O: OptionSetType where O.RawValue == UInt32>(inout lhs: O, rhs: O) {
lhs = O(rawValue: lhs.rawValue ^ rhs.rawValue)
}
func +=<O: OptionSetType where O.RawValue == UInt32>(inout lhs: O, rhs: O) {
lhs = O(rawValue: lhs.rawValue | rhs.rawValue)
}
func +<O: OptionSetType where O.RawValue == UInt32>(lhs: O, rhs: O) -> O {
return O(rawValue: lhs.rawValue | rhs.rawValue)
}
func -<O: OptionSetType where O.RawValue == UInt32>(lhs: O, rhs: O) -> O {
return O(rawValue: lhs.rawValue ^ rhs.rawValue)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment