I have a std::map<string, double>
whose members look something like:
X = [{"N", 200}, {"sigma", 1.0}, {"T", .2}]
Now, given the struct foo Y
:
struct foo {
int N;
double T;
};
Can I programmatically map the key/value pairs X -> Y
without writing a custom class for each X -> Y
type mapping? Note that:
X["sigma"]
is not inY
, i.e. the mapping is not necessarily one-to-one- The type of
Y.N
is an int whileX["N"]
is a double.
I suspect the answer is no, unless some trickery is done at compile time.
Edit: It may not be clear what I'm looking for. A pseudo-code version for this example would look something like:
if("N" in X) -> Y.N = X["N"];
if("T" in X) -> Y.T = X["T"];
Or programmatically:
for key in Y:
if (key in X) -> Y.key = X[key]