Most of the Swift SIMD float types have +-*/ operators, so we can just calculator the sum like below:
import simd
float2(2.0) + float2(2.0) // float2(4.0, 4.0)
float4(2.0) + float4(2.0) // float4(4.0, 4.0, 4.0, 4.0)
Now, Lets say I have a generic function that takes a pair of float2, float3 or float4 as arguments and returns the sum of them:
func calculateSum<T: SomeProtocolCoversThoseFloats>(a: T, b: T) -> {
return a + b
}
Is there any protocol that functions like this "SomeProtocolCoversThoseFloats" or is there any way that I can create such a protocol?