在数组查找中使用数组查找

时间:2019-03-28 19:31:11

标签: system-verilog

有没有一种方法可以将数组定位器函数用作数组定位器函数的条件?类似于以下内容:

我知道我可以简单地遍历数组,但是我希望有一个更简洁的方法

module tb;
  typedef struct {
    string name;
    int id;
  } positions_t;

  typedef struct {
    positions_t positions[];
    string unit_name;
  } injector_t;

  injector_t injectors[$] = '{
    '{
      unit_name: "unit1",
      positions: '{
        '{name: "ha", id:0},
        '{name: "he", id:0},
        '{name: "hi", id:0}
      }
    }
  };

  injector_t filtered_injectors[$];

  initial begin
    // LIKE THIS!
    filtered_injectors = injectors.find with (
      item.positions.find with (item.name == "hi")
    );
    $display("filtered list = %p", filtered_injectors);
  end
endmodule

1 个答案:

答案 0 :(得分:0)

find返回一个队列,因此这似乎可行

filtered_injectors = injectors.find with (
  item.positions.find with (item.name == "hi") != {}
);