isBinaryInteger, isSignedNumeric, isFloatingPoint: anyway to reduce boilerplate?

I learn how to do isBinaryInteger by @Nevin

I also needed isSignedNumeric and isFloatingPoint, which is just copy boilerplate of the original code:

protocol SignedNumericConformanceMarker { }
enum SignedNumericMarker<T> { }
extension SignedNumericMarker: SignedNumericConformanceMarker where T: SignedNumeric {}

func isSignedNumericType<T>(_ t: T.Type) -> Bool {
    SignedNumericMarker<T>.self is SignedNumericConformanceMarker.Type

func isSignedNumeric<T>(_ t: T) -> Bool {

protocol FloatingPointConformanceMarker {}
enum FloatingPointMarker<T> {}
extension FloatingPointMarker: FloatingPointConformanceMarker where T: FloatingPoint {}

func isFloatingPointType<T>(_ t: T.Type) -> Bool {
    FloatingPointMarker<T>.self is FloatingPointConformanceMarker.Type

func isFloatingPoint<T>(_ t: T) -> Bool {

Is there anyway to avoid the boilerplate?

Terms of Service

Privacy Policy

Cookie Policy