Is it possible to do math with structs?

Let’s say I have some kind of struct like the example below, which I use to keep track of items in my inventory

USTRUCT()
struct ExampleItemStruct{
GENERATED_USTRUCT_BODY()
AActor* myOwner;
int32 itemCount;
float itemValue;
float itemWeight;
}

At the bottom of my inventory panel, I want a little display that displays the total value and weight of everything in my inventory- is there any way I could achieve this by summing structs directly, like this?

ExampleItemStruct sumStruct;
for(int32 i = 0; i < ItemStructList.Num(); i++){
sumStruct+=ItemStructList[i];
}

The obvious alternative would be to manually iterate through every value, and do something like

for(int32 i = 0; i < ItemStructList.Num(); i++){
sumStruct.itemCount+=ItemStructList[i].itemCount;
sumStruct.itemValue+=ItemStructList[i].itemValue;
sumStruct.itemWeight+=ItemStructList[i].itemWeight;
}

But that’s clumsy in comparison, and I don’t want to be wasteful and manually iterate over every field if I don’t have to.

You could use operator overloading to make your first idea work:

USTRUCT()
struct ExampleItemStruct{
   GENERATED_USTRUCT_BODY()
   AActor* myOwner;
   int32 itemCount;
   float itemValue;
   float itemWeight;

   ExampleItemStruct& operator+=(const ExampleItemStruct& rhs)
   {
      itemCount += rhs.itemCount;
      itemValue += rhs.itemValue;
      itemWeight += rhs.itemWeight;
      return *this;
   }

   friend ExampleItemStruct operator+(ExampleItemStruct lhs, const ExampleItemStruct& rhs)
   {
      return lhs += rhs;
   }
}

This is exactly what I was looking for; thank you!!