How to correctly use a Template function?

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

In reply to Broxigar:

What issues are you having?

The following seems to work:


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

typedef enum int {ZERO=0, ONE=1, TWO=2} custom_type;

module testbench();

  initial begin
    automatic custom_type array[] = new[0];
    array = new[array.size() + 4](array);
    array[0] = ZERO;
    array[1] = ONE;
    array[2] = TWO;
    array[3] = ZERO;
    
    $display("array is %p", array);

    container #(.T(custom_type))::pop(array,1); 
  
    $display("array is %p", array);
  end
endmodule