Boost logo

Boost Users :

From: Christoph Duelli (duelli_at_[hidden])
Date: 2007-03-08 10:50:27


Given a struct like
  struct X { int a; char b; float c; }
and some function-'template' f

is it possible to 'generate' - preferably by means of templates, MPL or
something of the kind - variations of some function f for each of X's
fields?

E.g. I'd like to have functions like
int getA() { return a; }
char getB() { return b; }
float getC() { return c; }
...

(The functions I have in mind are more complex, obviously, but the idea is
to generate one such function for all the fields of X.)
I would like to avoid writing a macro call or something per field, as I
would like the code to work (after recompiling it) even if the definition
of X is changed and some fields are added.
So, is there some generic 'iterator' over the fields of a struct?

Thank you and best regards
Christoph


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net