Arun D'souza
Arun D'souza

Reputation: 202

Merging associative arrays

Assuming I have two associative arrays, is there a way to use something like a concatenation operator to merge them? I tried this, and it doesn't work:

module tb;
  initial begin
    int a[int] = '{1:1, 2:2};
    int b[int] = '{3:3, 4:4};
    $display("a = ", a);
    $display("b = ", b);
    b = {a,b};
    $display("b = ", b);
  end
endmodule

I know I can iterate over it and assign, but I'm essentially looking for a one-liner if it's doable. I couldn't find anything in the LRM.

Upvotes: 2

Views: 762

Answers (1)

dave_59
dave_59

Reputation: 42698

No, the LRM specifically excludes associative arrays from array concatenation (section 10.10).

A target of any other type (including associative array) shall be illegal.

It's also illegal to use any kind of casting. You'll have to use a foreach loop.

Upvotes: 3

Related Questions