From fd9e5dda784d0a7a79966e4f2adbf14462868ff6 Mon Sep 17 00:00:00 2001 From: Timerix Date: Mon, 3 Feb 2025 12:29:31 +0500 Subject: [PATCH] List_tryRemoveAt --- src/collections/List.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/collections/List.h b/src/collections/List.h index 545fe7f..4bdabab 100644 --- a/src/collections/List.h +++ b/src/collections/List.h @@ -20,6 +20,7 @@ T* List_##T##_expand(List_##T* ptr, u32 count);\ void List_##T##_push(List_##T* ptr, T value);\ void List_##T##_pushMany(List_##T* ptr, T* values, u32 count);\ + bool List_##T##_tryRemoveAt(List_##T* ptr, u32 i);\ #define List_define(T)\ @@ -52,6 +53,17 @@ T* empty_cell_ptr = List_##T##_expand(ptr, count);\ memcpy(empty_cell_ptr, values, count * sizeof(T));\ }\ + \ + bool List_##T##_tryRemoveAt(List_##T* ptr, u32 i){\ + if(ptr->len == 0 || i >= ptr->len)\ + return false;\ + \ + ptr->len--;\ + for(; i < ptr->len; i++){\ + ptr->data[i] = ptr->data[i + 1];\ + }\ + return true;\ + }\ List_declare(u32);