I forgot to reply to the email list here. > On Dec 26, 2016, at 10:03 PM, Xiaodi Wu <[email protected] > <mailto:[email protected]>> wrote: > > Did you mean to reply offlist? > > Basically, a factory would be: > > func make<T>(_: T.Type) -> T { return T() } > > but you need T to conform to a protocol that guarantees T.init(). You use it > like: > > make(Foo.self) > > But one can write: > > func make<T>(_ f: @autoclosure () -> T) -> T { return f() } > > and use this like: > > make(Foo()) > > (pardon typos; freehanding on iPad) > > > > On Mon, Dec 26, 2016 at 23:58 Braeden Profile <[email protected] > <mailto:[email protected]>> wrote: > Actually, I’m a little lost at this point of exactly how you could build a > function with this pattern. Code, anyone? > >> On Dec 26, 2016, at 9:57 PM, Xiaodi Wu <[email protected] >> <mailto:[email protected]>> wrote: >> >> With @autoclosure your user can simply write T() as an argument. It is very >> elegant and not complicated at all.
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
