I wish to create a custom function that takes as an argument a dynamic array of whatever type (Type T) (pass-by-reference) and an index (int) and deletes an element at index.
I have followed the code proposed as a solution here and came up with the following.
So, in my utility package that I import on my TestBench file I have the following code for this function:
class container #(type T);
static function automatic void pop(ref T array[], input int id);
T temp [] = new [0];
for (int unsigned index = 0, int unsigned new_index = 0; index < array.size(); index++) begin
if (index != id) begin
temp = new [temp.size() + 1](temp);
temp[new_index] = array[index];
new_index = new_index + 1;
end
end
array = temp;
endfunction
endclass
But I am having issues invoking this code in my TestBench. I try to invoke it as
typedef enum int {ZERO=0, ONE=1, TWO=2} custom_type;
custom_type array[] = new[0];
array = new[array.size() + 4](array);
array[0] = ZERO;
array[1] = ONE;
array[2] = ONE;
array[3] = TWO;
container #(.T(custom_type))::pop(array,1);
What is the correct way of using it?
Thank you in advance