I do have 2 different tuples of type (Double, Double):
let tuple1: (Double, Double) = (1, 2)
let tuple2: (Double, Double) = (3, 4)
I want t
The following approach compares tuple of any number of members of any size, provided they do not contain collection types like Array
and Dictionary
.
import Darwin // or Foundation
/// here we go
func memeq(var lhs: T, var rhs: T) -> Bool {
return withUnsafePointers(&lhs, &rhs) {
memcmp($0, $1, UInt(sizeof(T)))
} == 0
}
let l = (false, 42, log(exp(1.0)))
let r = (!true, 6*7, exp(log(1.0)))
println(memeq(l, r)) // expectedly true
let l2 = (0, [0])
let r2 = (0, [0])
println(memeq(l2, r2)) // unfortunately false
Note types are already checked via generics. If they differ, it does not even compile thanks to type checking.