diff options
| author | gingerBill <bill@gingerbill.org> | 2020-06-22 13:25:19 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-06-22 13:25:19 +0100 |
| commit | fb3aeccd361c1702ff2de92860884782e5d60bdd (patch) | |
| tree | b9750a8e6cba49419e68413bf05ca5d52ee4d22c /core/runtime | |
| parent | 9495e3d10c8a8314e0bbd683338ce98d45b14ac2 (diff) | |
Add built-in `Maybe`
Diffstat (limited to 'core/runtime')
| -rw-r--r-- | core/runtime/core.odin | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/core/runtime/core.odin b/core/runtime/core.odin index fd7144d41..5cad2d5cd 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -310,6 +310,9 @@ Context :: struct { } +@builtin +Maybe :: union(T: typeid) #maybe {T}; + @thread_local global_default_temp_allocator_data: Default_Temp_Allocator; @@ -554,6 +557,19 @@ ordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_locati pop(array); } +@builtin +pop_front :: proc(array: ^$T/[dynamic]$E) -> (E, bool) #no_bounds_check { + if len(array) == 0 { + return E{}, false; + } + res := array[0]; + if len(array) > 1 { + copy(array[0:], array[1:]); + } + (^Raw_Dynamic_Array)(array).len -= 1; + return res, true; +} + @builtin clear :: proc{clear_dynamic_array, clear_map}; |