Sum query on a Multi D array

In reply to dave_59:

Hi Dave,

So changing my example, is the following supposed to work? I want it to behave the same as my other example above.

module tb;
  
class twod;
  rand bit [7:0] cells[5][5];
  
  constraint c {
    // constrain the first two columns of cells to add up to 30
    foreach ( cells[r,c] ) {
      cells[r][c] inside { 5,10,15,20 };
      cells[r].sum() with ( item.index < 2 ? item : 0 ) == 30;
    }
  }
  
  function void show();
      $write("cells\n");
      foreach ( cells[r,c] ) begin
        $write( "%3d ", cells[r][c] );
        if ( c == 4 )
          $write("\n");
      end
  endfunction
      
      
endclass

initial begin
  automatic twod td = new;
  $display( "randomize == %0b\n", td.randomize() );
  td.show();
end
      
endmodule