formIndex(_:offsetBy:limitedBy:)
Offsets the given index by the specified distance, but no further than the given limiting index.
Declaration
func formIndex(_ index: inout UniqueArray<Element>.Index, offsetBy n: inout Int, limitedBy limit: UniqueArray<Element>.Index)Parameters
- index:
A valid index of the array. On return,
indexis set to the resulting position. - n:
The distance to offset
index. On return,nis set to zero if the operation succeeded without hitting the limit; otherwise,nreflects the number of steps that couldn’t be taken. - limit:
A valid index of the array to use as a limit. If
n > 0, a limit that is less thanindexhas no effect. Likewise, ifn < 0, a limit that is greater thanindexhas no effect.
Discussion
If the operation was able to offset index by exactly the requested number of steps without hitting limit, then on return n is set to 0, and index is set to the adjusted index.
If the operation hits the limit before it can take the requested number of steps, then on return index is set to limit, and n is set to the number of steps that couldn’t be taken.
The value passed as n must not offset index beyond the bounds of the container, unless the index passed as limit prevents offsetting beyond those bounds.