[swift-evolution] [Pitch] UnsafePointer.advanced(to:)

Xiaodi Wu xiaodi.wu at gmail.com
Tue Jun 6 11:06:00 CDT 2017


Why would this be an extension on UnsafePointer and not KeyPath?
On Tue, Jun 6, 2017 at 10:28 Brent Royal-Gordon via swift-evolution <
swift-evolution at swift.org> wrote:

> It won't happen for Swift 4, but I think we should eventually have APIs
> like:
>
> extension UnsafePointer {
>     func advanced<T>(to keyPath: KeyPath<Pointee, T>) -> UnsafePointer<T>?
> }
>
> If keyPath referred to a stored property directly inside the value, this
> would return a pointer to that property. If keyPath is a computed property,
> or the property is not stored relative to the pointer (e.g. an object or
> indirect pointer), it returns nil.
>
> My most immediate use case is for working with MIDI structures, which have
> an inline byte buffer, but I suspect there will be other uses as well.
>
> --
> Brent Royal-Gordon
> Sent from my iPhone
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170606/a8f131cc/attachment.html>


More information about the swift-evolution mailing list