I am trying to write a generic function that requires bit shifting operations. I get behavior that I don't understand. Here is a simple function that demonstrates the problem.
func testBytes<T: IntegerType>(bytesIn: [UInt8], inout dataOut: T){ let outputSize = sizeof(T) var temp: T = 0 dataOut = 0 temp = bytesIn[0] as T temp = temp << 1 }
If I do this, the last line will give me an error in xcode "T does not convert to Int".
I can change the last line to temp = temp << (1 as T)
And then the error for this line will change to "T does not convert to UInt8"
None of these error messages make sense to me in this context. Is there something I can do to enable bit offsets on a generic type?
source share