summaryrefslogtreecommitdiff
path: root/ds.h
diff options
context:
space:
mode:
Diffstat (limited to 'ds.h')
-rw-r--r--ds.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/ds.h b/ds.h
index 397dcfa..a588be7 100644
--- a/ds.h
+++ b/ds.h
@@ -192,6 +192,13 @@ static void *arr_remove_(void *arr, size_t member_size, size_t index) {
}
}
+static void *arr_copy_(const void *arr, size_t member_size) {
+ void *new_arr = NULL;
+ arr_set_len_(&new_arr, member_size, arr_len(arr));
+ memcpy(new_arr, arr, member_size * arr_len(arr));
+ return new_arr;
+}
+
#ifdef __cplusplus
#define arr_cast_typeof(a) (decltype(a))
#elif defined __GNUC__
@@ -224,6 +231,7 @@ static void *arr_remove_(void *arr, size_t member_size, size_t index) {
#define arr_pop_last(a) ((a)[--arr_hdr_(a)->len])
#define arr_size_in_bytes(a) (arr_len(a) * sizeof *(a))
#define arr_lastp(a) ((a) ? &(a)[arr_len(a)-1] : NULL)
+#define arr_copy(a) arr_cast_typeof(a) arr_copy_((a), sizeof *(a))
#define arr_foreach_ptr_end(a, type, var, end) type *end = (a) + arr_len(a); \
for (type *var = (a); var != end; ++var)
// Iterate through each element of the array, setting var to a pointer to the element.