Contents

append(addingCapacity:initializingWith:)

Grows the array to have enough capacity for the specified number of elements, then calls the closure with an output span covering the array’s uninitialized memory.

Declaration

mutating func append<E>(addingCapacity uninitializedCount: Int, initializingWith initializer: (inout OutputSpan<Element>) throws(E) -> Void) throws(E) where E : Error

Parameters

  • uninitializedCount:

    The number of new elements the array should have space for.

  • initializer:

    A closure that initializes new elements.

    • Parameters:

      • span: An OutputSpan covering uninitialized memory with space for the specified number of additional elements.

Discussion

Inside the closure, initialize elements by appending to span. It ensures safety by keeping track of the initialization state of the memory At the end of the closure, span’s count elements will have been appended to the array.

If the closure throws an error, the items appended until that point will remain in the array.