init(_:)
Initializes every element in this array, by calling the given closure with each index.
Declaration
init<E>(_ body: (InlineArray<count, Element>.Index) throws(E) -> Element) throws(E) where E : ErrorParameters
- body:
A closure that returns an owned
Elementto emplace at the passed in index.
Discussion
This will call the closure count times, where count is the static count of the array, to initialize every element by passing the closure the index of the current element being initialized.
InlineArray<4, Int> { $0 * 2 } // [0, 2, 4, 6]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.