Consider the following code.
struct Data {
int a = 100;
char* b = nullptr;
};
struct Data2 {
int c = 100;
char* d = nullptr;
};
template<typename T>
struct Test {
T field;
T field2;
};
int main()
{
Test<Data> test;
test.field.a = 500;
test.field2.a = 500;
Test<Data2> test2;
test2.field.c = 1000;
test2.field2.c = 1000;
}
What I'd like to have is a method or operator to do something like
test.set<a> = {500, 500}
test2.set<c> = {1000, 1000}
Basically I'd like to somehow specify field name, go through all the struct fields and set the values from a given list of values.
I suspect the problem is insolvable with standard C++ (any standard) due to the absence of reflection mechanisms. Am I right with that assumption?