If you literally just want to know if something conforms to such a protocol, and you don’t need to actually use the conformance for anything, you can check like this:
protocol ConformanceMarker {}
enum BinaryIntegerMarker<T> {}
extension BinaryIntegerMarker: ConformanceMarker where T: BinaryInteger {}
func isBinaryIntegerType<T>(_ t: T.Type) -> Bool {
return BinaryIntegerMarker<T>.self is ConformanceMarker.Type
}
func isBinaryInteger<T>(_ t: T) -> Bool {
return isBinaryIntegerType(T.self)
}
If you actually want to use the conformance for something, it gets more tricky. See this thread for details.
Original strategy by Matt Johnson here (explanatory description by myself here)
Modular solution with better encapsulation properties by myself here (and the next comment after it)
Simple quick-and-dirty approach by Dave Abrahams here