Generic Instance Method

withContiguousStorageIfAvailable(_:)

Call body(p), where p is a pointer to the collection’s contiguous storage. If no such storage exists, it is first created. If the collection does not support an internal representation in a form of contiguous storage, body is not called and nil is returned.

Declaration

func withContiguousStorageIfAvailable<R>(_ body: (UnsafeBufferPointer<Element>) throws -> R) rethrows -> R?

Discussion

A Collection that provides its own implementation of this method must also guarantee that an equivalent buffer of its SubSequence can be generated by advancing the pointer by the distance to the slice’s startIndex.

Relationships

From Protocol

See Also

Accessing Underlying Storage

func withUnsafeBufferPointer<R>((UnsafeBufferPointer<Element>) -> R) -> R

Calls a closure with a pointer to the array’s contiguous storage.

func withUnsafeMutableBufferPointer<R>((inout UnsafeMutableBufferPointer<Element>) -> R) -> R

Calls the given closure with a pointer to the array’s mutable contiguous storage.

func withUnsafeBytes<R>((UnsafeRawBufferPointer) -> R) -> R

Calls the given closure with a pointer to the underlying bytes of the array’s contiguous storage.

func withUnsafeMutableBytes<R>((UnsafeMutableRawBufferPointer) -> R) -> R

Calls the given closure with a pointer to the underlying bytes of the array’s mutable contiguous storage.

func withContiguousMutableStorageIfAvailable<R>((inout UnsafeMutableBufferPointer<Element>) -> R) -> R?

Call body(p), where p is a pointer to the collection’s mutable contiguous storage. If no such storage exists, it is first created. If the collection does not support an internal representation in a form of mutable contiguous storage, body is not called and nil is returned.