如何从队列中匹配和删除元素?

How to match and delete an element from a queue?

根据1800-2012 specs

Queue::delete( [input int index] ) 

在 SystemVerilog 中删除队列的一个元素,此外,队列可以执行与解压缩数组相同的操作,使其可以访问:

Array::find_first_index( )

which returns 符合特定条件的第一个元素的索引。即

find_first_index( x ) with ( x == 3)

现在我想从队列中删除一个保证存在的唯一项。结合 1 和 1 得到:

queue.delete(queue.find_first_index( x ) with ( x == obj_to_del ));

虽然说传递的参数必须是整数或整数兼容,但编译器并不理解。我可能会把两者分开:

int index = queue.find_first_index( x ) with ( x == obj_to_del );
queue.delete( index );

或通过类型转换强制输入整数 find_first_index:

queue.delete(int'(queue.find_first_index( x ) with ( x == obj_to_del ))) //Just finished compiling, does not work.

前者在我看来不太优雅,而后者似乎有些勉强,这让我很好奇是否有更合适的方法来实现这一点。 find_first_index 是否可能返回一个大小为 1 且索引位于位置 0 的数组?

编辑:我愚蠢地没有提供一个独立的例子:我正在做的一个剥离的例子看起来像:

class parent_task;
endclass;

class child_taskA extends parent_task;
endclass;

class child_taskB extends parent_task;
endclass;    

class task_collector;

 child_taskA A_queue[$];
 child_taskB B_queue[$];

 function delete_from_queue(parent_task task_to_del);
      case (task_to_del.type):
         A: A_queue.delete(A_queue.find_first_index( x ) with ( x == task_to_del));
         B: B_queue.delete(B_queue.find_first_index( x ) with ( x == task_to_del));
         default: $display("This shouldn't happen.");
 endfunction
endclass

逐字逐句的错误信息是:

Error-[SV-IQDA] Invalid Queue delete argument
"this.A_queue.find_first_index( iterator ) with ((iterator == task))"
 Queue method delete can take optional integer argument. So, argument passed
 to it must be either integer or integer assignment compatible.

在调用 delete_from_queue.

之前进行检查以确保相关任务存在
queue.delete(int'(queue.find_first_index( x ) with ( x == obj_to_del )));

适合我。如果您能提供像下面这样的完整的自包含示例,那将非常有帮助:

module top;
   int queue[$] = {1,2,3,4,5};
   let object_to_del = 3;
       initial begin
      queue.delete(int'(queue.find_first_index( x ) with ( x == object_to_del )));
      $display("%p", queue);
       end
endmodule

但是如果没有匹配怎么办?在删除之前是否不需要测试 find_first_index() 的结果?

int cast 对我也不起作用,但下面的方法有效

int index_to_del[$];

index_to_del = que.find_first_index(x) with ( x == task_to_del );
que.delete(index_to_del[0]);