[swift-evolution] [Discussion] Seal `T.Type` into `Type<T>`

Anton Zhilin antonyzhilin at gmail.com
Wed Jul 13 11:30:52 CDT 2016


I see model of Type<T> as follows:

   1. Values of Type<T> are identifiers of types (8 bytes, I guess)
   2. All used identifiers are contained in Type<Any>
   3. Type<T> contains a subset of those identifiers
   4. Type<T> are usually created with default constructor Type<T>()
   5. Upcasting uses constructor init<U: T>(upcasting: Type<U>)
   6. Checking for conformance uses method isSubtype(of:)
   7. Size of Type<Type<T>> is 8, static size of Type<SomeProtocol> is 0

2016-07-13 18:25 GMT+03:00 Adrian Zubarev via swift-evolution <
swift-evolution at swift.org>:
>
> a = SomeClass.self
>
> expectTrue(a as? Any.Type == SomeClass.self)
> expectTrue(a as? AnyClass == SomeClass.self)
> expectTrue(a as? SomeClass.Type == SomeClass.self)
>
> That example just demonstrates syntax of metatypes and does not count.

>
>    -
>
>    What about dynamicType?
>
> It should have the following signature:

func dynamicType<T>(_ var: T) -> Type<T>

To return Type<T> means to return an identifier of U: T
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160713/c89492de/attachment.html>


More information about the swift-evolution mailing list