This package contains three generic types UnsignedValue<Storage, Unit>, SignedValue<Storage, Unit>, FloatingValue<Storage, Unit>. These can be used to implement typesafe numeric values so that you can’t accidentally add two values with different types (Units). The Storage parameter is used to specify the backing arithmetic type (signed, unsigned, floating respectively) for each value. The Unit parameter is a phantom type, used for compile time type checking of the units.
Phantomlike
This package contains three generic types
UnsignedValue<Storage, Unit>
,SignedValue<Storage, Unit>
,FloatingValue<Storage, Unit>
. These can be used to implement typesafe numeric values so that you can’t accidentally add two values with different types (Units
). TheStorage
parameter is used to specify the backing arithmetic type (signed, unsigned, floating respectively) for each value. TheUnit
parameter is a phantom type, used for compile time type checking of the units.Installation
Use Swift Package Manager.
Usage
Other considerations
Note that the compiler will let you add a typealias and a literal of the
Storage
type. E.g.However
This should not be an issue but watch out for it.