diff --git a/array/static_array.jai b/array/static_array.jai index 0ff24a0..117589b 100644 --- a/array/static_array.jai +++ b/array/static_array.jai @@ -5,28 +5,6 @@ Static_Array :: struct(capacity: int, T: Type) { Default :: #run mem.default_of(T); } -operator [] :: inline (a: Static_Array, $$index: int, loc := #caller_location) -> a.T #no_abc { - meta.check_bounds(index, a.count, loc = loc); - return a.items[index]; -} - -operator *[] :: inline (a: *Static_Array, $$index: int, loc := #caller_location) -> *a.T #no_abc { - meta.check_bounds(index, a.count, loc = loc); - return *a.items[index]; -} - -operator []= :: inline (a: *Static_Array, $$index: int, value: a.T, loc := #caller_location) #no_abc { - meta.check_bounds(index, a.count, loc = loc); - a.items[index] = value; -} - -for_expansion :: (a: *Static_Array, body: Code, flags: For_Flags) #expand { - view := make_view(a); - for *=(flags & .POINTER == .POINTER) <=(flags & .REVERSE == .REVERSE) `it, `it_index: view { - #insert,scope(body)(break = break it) body; - } -} - append :: inline (a: *Static_Array, item: a.T) -> *a.T #no_abc { ensure_array_has_room(a, 1); ptr := *a.items[a.count]; @@ -55,6 +33,28 @@ reset :: inline (a: *Static_Array) #no_abc { a.count = 0; } +operator [] :: inline (a: Static_Array, $$index: int, loc := #caller_location) -> a.T #no_abc { + meta.check_bounds(index, a.count, loc = loc); + return a.items[index]; +} + +operator *[] :: inline (a: *Static_Array, $$index: int, loc := #caller_location) -> *a.T #no_abc { + meta.check_bounds(index, a.count, loc = loc); + return *a.items[index]; +} + +operator []= :: inline (a: *Static_Array, $$index: int, value: a.T, loc := #caller_location) #no_abc { + meta.check_bounds(index, a.count, loc = loc); + a.items[index] = value; +} + +for_expansion :: (a: *Static_Array, body: Code, flags: For_Flags) #expand { + view := make_view(a); + for *=(flags & .POINTER == .POINTER) <=(flags & .REVERSE == .REVERSE) `it, `it_index: view { + #insert,scope(body)(break = break it) body; + } +} + make_view :: (a: Static_Array) -> []a.T { view := a.items.([]a.T); view.count = a.count;