Browse Source

Add `slice.enumerated_array`

gingerBill 2 years ago
parent
commit
c056a0d108
1 changed files with 7 additions and 0 deletions
  1. 7 0
      core/slice/slice.odin

+ 7 - 0
core/slice/slice.odin

@@ -509,3 +509,10 @@ dot_product :: proc(a, b: $S/[]$T) -> (r: T, ok: bool)
 	}
 	return r, true
 }
+
+
+// Convert a pointer to an enumerated array to a slice of the element type
+enumerated_array :: proc(ptr: ^$T) -> []intrinsics.type_elem_type(T)
+	where intrinsics.type_is_enumerated_array(T) {
+	return ([^]intrinsics.type_elem_type(T))(ptr)[:len(T)]
+}