Suppose I have a struct, such as:
struct Foo {
double a;
float b;
int c;
};
Summing fooA
and fooB
(both of type Foo
) would equate to:
{fooA.a + fooB.a,
fooA.b + fooB.b,
fooA.c + fooB.c};
Now my question is, could a generic function be created that would sum structs together in this manner? i.e.:
template <typename StructType>
StructType sumStructs(StructType A, StructType B) {
// sum component with one another, return resulting struct
}
Alternatively, what limitations would you need to impose for it to be possible?