init(first:next:)
Initializes every element in this array, by calling the given closure with each preceding element.
Declaration
init<E>(first: consuming Element, next: (borrowing Element) throws(E) -> Element) throws(E) where E : ErrorParameters
- first:
The first value to emplace into the array.
- next:
A closure that takes an immutable borrow reference to the preceding element, and returns an owned
Elementinstance to emplace into the array.
Discussion
This will call the closure count - 1 times, where count is the static count of the array, to initialize every element by passing the closure an immutable borrow reference to the preceding element.
InlineArray<4, Int>(first: 1) { $0 * 2 } // [1, 2, 4, 8]The closure is allowed to throw an error at any point during initialization at which point the array will stop initialization, deinitialize every currently initialized element, and throw the given error back out to the caller.