nupp.mem.indexed
One inclusive range, checked once against every view a loop is about to index.
A loop that walks two views together needs the same bounds to hold for both, and checking them separately checks them twice and says nothing about the pair. range takes the views and answers bounds that are valid for all of them.
local indexed = nupp.mem.indexed
const bounds = indexed.range(1, 4, left, right)
for i = bounds.first, bounds.last do
print(left[i], right[i])
endThe checker validates the variadic operands against their trusted descriptors, so only a sealed view contract can be passed. The runtime body stays representation-neutral and reads the private count slot each bundled view implementation carries.
See nupp.mem.span for the views this validates, and ownership.md for the borrow rules they are written against.
Module contents
Types
| Type | Kind | Description |
|---|---|---|
Range | record | Inclusive integer bounds validated once against every supplied indexed view. |
Functions
| Function | Kind | Description |
|---|---|---|
range | function | Validates one inclusive range against every view supplied after it. |
Types#
Rangerecord#
Inclusive integer bounds validated once against every supplied indexed view.
Fields
Functions#
indexed.rangefunction#
Validates one inclusive range against every view supplied after it.
At least one view is required: bounds nothing was checked against are not bounds. The views are borrowed for the call, so this may be written inline in the for header that uses the result.
const bounds = indexed.range(1, 4, left, right)
for i = bounds.first, bounds.last do
print(left[i], right[i])
endArguments
| Name | Type | Description |
|---|---|---|
first | integer | the one-based first index, inclusive |
last | integer | the one-based last index, inclusive |
borrows ... | any |
Returns
| Type | Description |
|---|---|
indexed.Range | the validated bounds |
Raises
when no view is supplied or the bounds exceed a supplied view