How to ensure specialized generic function is being used?

This would compile if you had declared an overload of asd like the following (which takes the type of the protocol A, not a type conforming to the protocol A):

func asd(_: A.Type) { print("asd(_: A.Type) called") }

But again, I fail to see what it has to do with your original question.


I think what you need to understand is exemplified by this program:

func zxc<T>(_: T.Type) {
    // There is *runtime* info about `T` here, so we can print its type:
    print("Printing runtime type of `T` from zxc:\n ", T.self)
    // But at compile time, nothing is known about `T` here, because
    // `T` is totally unconstrained. So this:
    print("Calling qaz(T.self) from zxc:")
    qaz(T.self)
    // Will only be able to call a qaz for a totally unconstrained type.
    // So it will always, no matter the runtime type of T, be calling
    // qaz<T>(), and never eg qaz<T: Numeric>().
}

func qaz<T>(_: T.Type) { print("  qaz<T>()") }

func qaz<T: Numeric>(_: T.Type) { print("  qaz<T: Numeric>()") }

func test() {
    zxc(Int.self)
    print("Calling qaz(Int.self) from test:")
    qaz(Int.self)
}
test()

Which will print:

Printing runtime type of `T` from zxc:
  Int
Calling qaz(T.self) from zxc:
  qaz<T>()
Calling qaz(Int.self) from test:
  qaz<T: Numeric>()

Remember that Swift's generics is not like eg C++ templates.