> On Jul 5, 2016, at 5:26 AM, Anton Zhilin <[email protected]> wrote:
> 
> func initialize<T>(_: T.Type, to: T, count: Int = 1)
>     -> UnsafeMutablePointer<T>
> 
> I wonder why the first parameter is needed. If one is passing literals, it's 
> always more Swift'y to use 'as'.


From the proposal:

---
The type parameter `T` passed to `initialize` is an explicit argument
because the user must reason about the type's size and alignment at
the point of initialization. Inferring the type from the value passed
to the second argument could result in miscompilation if the inferred
type ever deviates from the user's original expectations.
—

You can think of this as the “raw” API. With the latest proposal, it will be 
more common for users to initialize with a typed pointer anyway:

ptrToA.initialize(to: A())

-Andy
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to