Array methods on array of objects- is it allowed?

Hi,

Are array methods like arr.sum(), or arr.shuffle(), arr.find() etc allowed on dynamic array of objects? Or do they give out an error?

Thank you.

In reply to DK87:

Not according to the current LRM which says it can only be applied to arrays of integral types.
But all versions I tried support this as long as the with clause returns a type valid for the reduction operator.

module top;
class A;
   rand bit[7:0] b;
endclass
   A array[10];
   initial begin
      foreach(array[ii]) begin
	 array[ii] = new;
	 void'(array[ii].randomize());
	 $write("array[%0d]=%d ",ii,array[ii].b);
     
      end
      $display("\n sum = %d",array.sum() with (int'(item.b)));
   end
endmodule

This requested in 0001690: Array reduction methods for non-integral types - Accellera Mantis

In reply to dave_59:

This is really cool! I didn’t know we could do a sum on objects variables using with. Thank you Dave!