Question for bitwise operator
Opened this issue · 0 comments
oozoofrog commented
Thanks. this source is very brilliant.
I have a question for bitwise - like or(|) - operator overloading.
First time, i just added function like,
public func | <T:IntNumberConvertible, U:IntNumberConvertible,V:IntNumberConvertible>(lhs: T, rhs: U) -> V {
return lhs.operate(rhs, combine: |)
}
but, sadly, this is return ambiguous error on compile
so i added few more codes like,
extension IntNumberConvertible {
private typealias CombineIntType = (UInt, UInt) -> UInt
private func operate<T:IntNumberConvertible,V:IntNumberConvertible>(b:T, combine:CombineIntType) -> V{
let x:UInt = self.convert()
let y:UInt = b.convert()
return combine(x,y).convert()
}
}
public func | <T:IntNumberConvertible, U:IntNumberConvertible,V:IntNumberConvertible>(lhs: T, rhs: U) -> V {
return lhs.operate(rhs, combine: |)
}
and, it's working.
I hate another extension and overloading. can i have more efficient way?