Now, we want to be able to use any of the integer types as types in our MutableVector3D<T>
and ImmutableVector3D<T>
classes. We want to make the two classes capable of working with elements of any integer type supported in Swift, that is, any of the following types, in addition to the floating point types that the classes already support:
Int
Int16
Int32
Int64
Int8
UInt
UInt16
UInt32
UInt64
UInt8
It seems to be a pretty simple task. We would just have to replace the generic type constraint in each class declaration from FloatingPoint
to a more generic protocol. We need a protocol to which all the previously enumerated types conform to, and to which the floating point types also conform. However, we will face a big problem: we don't have a protocol that will allow us to easily build the generic type constraint and make the two classes work. Let's analyze the problem first and then we will build a solution.
All the types...