I would like to have “assignment or” and “assignment and” operators. According to the Swift Standard Library Operators Reference , these operators are defined in the standard library.
I tried to implement these operators for values Bool:
func ||= (inout lhs: Bool, rhs: Bool) {
lhs = lhs || rhs
}
func &&= (inout lhs: Bool, rhs: Bool) {
lhs = lhs && rhs
}
But the compiler complains: operator implementation without matching operator declaration
This can be fixed by defining the operators:
infix operator ||= { associativity right precedence 90 }
infix operator &&= { associativity right precedence 90 }
But I'm not sure if this is the right thing. Why definitions from the standard library do not work? In addition, I noticed that in accordance with standard standards, the operator library does not have implementations of these operators for any type. Why is this? Is this oversight or something intentional?