Contents

initialize(fromContentsOf:)

Initializes the buffer slice’s memory with with every element of the source.

Declaration

func initialize<Element>(fromContentsOf source: some Collection) -> Slice<Base>.Index where Base == UnsafeMutableBufferPointer<Element>

Parameters

  • source:

    A collection of elements to be used to initialize the buffer slice’s storage.

Return Value

The index one past the last element of the buffer slice initialized by this function.

Discussion

Prior to calling the initialize(fromContentsOf:) method on a buffer slice, the memory it references must be uninitialized, or the Element type must be a trivial type. After the call, the memory referenced by the buffer slice up to, but not including, the returned index is initialized. The buffer slice must reference enough memory to accommodate source.count elements.

The returned index is the index of the next uninitialized element in the buffer slice, one past the index of the last element written. If source contains no elements, the returned index is equal to the buffer slice’s startIndex. If source contains as many elements as the buffer slice can hold, the returned index is equal to to the slice’s endIndex.