FixedSizeArray

public protocol FixedSizeArray:
  MutableCollection, RandomAccessCollection, SourceInitializableCollection,
  CustomStringConvertible where Index == Int

Statically-sized nonempty collections of homogeneous elements.

This protocol is mostly an implementation detail of ArrayN; it is not generally useful. Unless you’re interested in generic application of inserting/removing, you probably want to use RandomAccessCollection/MutableCollection (either as constraints or conformances).

The models of FixedSizeArray defined here efficiently support producing new instances by single-element insertion and deletion.

  • Creates an instance containing exactly the elements of source.

    Requires: source.count == c, where c is the capacity of instances.

    Declaration

    Swift

    init<Source>(_ source: Source) where Source : Collection, Self.Element == Source.Element
  • Creates an instance containing the elements of source except the one at targetPosition.

    Requires: source.indices.contains(targetPosition)

    Declaration

    Swift

    init(_ source: ArrayN<Self>, removingAt targetPosition: Index)
  • Returns a fixed-sized collection containing the same elements as self, with newElement inserted at targetPosition.

    Declaration

    Swift

    func inserting(_ newElement: Element, at targetPosition: Index) -> ArrayN<Self>
  • The number of elements in an instance.

    Declaration

    Swift

    static var count: Int { get }
  • description Extension method

    Default implementation of CustomStringConvertible conformance.

    Declaration

    Swift

    var description: String { get }
  • withUnsafeBufferPointer(_:) Extension method

    Returns the result of calling body on the elements of self.

    Declaration

    Swift

    func withUnsafeBufferPointer<R>(
      _ body: (UnsafeBufferPointer<Element>) throws -> R
    ) rethrows -> R
  • Returns the result of calling body on the elements of self.

    Declaration

    Swift

    mutating func withUnsafeMutableBufferPointer<R>(
      _ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
    ) rethrows -> R
  • Returns the result of calling body on the elements of self.

    Declaration

    Swift

    func withContiguousStorageIfAvailable<R>(
      _ body: (UnsafeBufferPointer<Element>) throws -> R
    ) rethrows -> R?
  • Returns the result of calling body on the elements of self.

    Declaration

    Swift

    mutating func withContiguousMutableStorageIfAvailable<R>(
      _ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
    ) rethrows -> R?
  • prepending(_:) Extension method

    Returns a fixed-sized collection containing the same elements as self, with newElement inserted at the start.

    Declaration

    Swift

    func prepending(_ newElement: Element) -> ArrayN<Self>