Skip to content

Intrinsic Procedure __access__

IsaacShelton edited this page Mar 21, 2022 · 1 revision

'__access__' method

The __access__ method can be defined to allow additional types to be used with the element access [] and pointer element access at operators.

func __access__(this *StructValue, index $I) *$T {

}

where

  • $T is the element type of the collection
  • $I is the index type

The return value is a pointer to the element identified by the given index value.

Example Definition

The following is a simple example of what a definition of the __access__ method might look like:

struct <$T> Array (items *$T, length usize) {
    
    /* ... other methods ... */

    func __access__(index usize) *$T = this.items at index
}

This example is a reduced version of the __access__ method for the standard Array type.

Clone this wiki locally