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])
end

The 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

TypeKindDescription
RangerecordInclusive integer bounds validated once against every supplied indexed view.

Functions

FunctionKindDescription
rangefunctionValidates one inclusive range against every view supplied after it.

Types#

Rangerecord#

record indexed.Range
    readonly first: integer
    readonly last: integer
end

Inclusive integer bounds validated once against every supplied indexed view.

Fields

first#
first: integer

The one-based first index, inclusive.

last#
last: integer

The one-based last index, inclusive. One below first is an empty range.

Functions#

indexed.rangefunction#

function indexed.range(first: integer, last: integer, borrows ?: any): indexed.Range

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])
end

Arguments

NameTypeDescription
firstinteger

the one-based first index, inclusive

lastinteger

the one-based last index, inclusive

borrows ...any

Returns

TypeDescription
indexed.Range

the validated bounds

Raises

  • when no view is supplied or the bounds exceed a supplied view