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
, wherec
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 attargetPosition
.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
, withnewElement
inserted attargetPosition
.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 methodDefault implementation of
CustomStringConvertible
conformance.Declaration
Swift
var description: String { get }
-
withUnsafeBufferPointer(_:
Extension method) Returns the result of calling
body
on the elements ofself
.Declaration
Swift
func withUnsafeBufferPointer<R>( _ body: (UnsafeBufferPointer<Element>) throws -> R ) rethrows -> R
-
withUnsafeMutableBufferPointer(_:
Extension method) Returns the result of calling
body
on the elements ofself
.Declaration
Swift
mutating func withUnsafeMutableBufferPointer<R>( _ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R ) rethrows -> R
-
withContiguousStorageIfAvailable(_:
Extension method) Returns the result of calling
body
on the elements ofself
.Declaration
Swift
func withContiguousStorageIfAvailable<R>( _ body: (UnsafeBufferPointer<Element>) throws -> R ) rethrows -> R?
-
withContiguousMutableStorageIfAvailable(_:
Extension method) Returns the result of calling
body
on the elements ofself
.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
, withnewElement
inserted at the start.Declaration
Swift
func prepending(_ newElement: Element) -> ArrayN<Self>