
On Sat, Dec 12, 2009 at 12:01 AM, Alex Vinokur
"OvermindDL1"
wrote in message news:3f49a9f40912111556w24850c47le205e9f9eb552cf5@mail.gmail.com... On Fri, Dec 11, 2009 at 10:45 AM, Alex Vinokur
wrote: Hi,
Does Boost contain any features to get metadata of classes?
For instance,
Let Foo be some class
class Foo { int m_var1; long* m_var2] char m_var3[100]; dooble m_var4; };
I would like to get the following info (as vector, file, etc) of its members:
{" m_var1", "int", sizeof (m_var1), offset of (m_var1) }, {" m_var2", "long", "Pointer", sizeof (m_var2), sizeof (base-variable, i.e., long), offset of (m_var2 }, {" m_var3, "char", "array", sizeof (m_var3), sizeof (base-variable, i.e., char), offset of (m_var3 }, {" m_var4", "double", sizeof (m_var4), offset of (m_var4) },
That info I would like to get as a result of some feature (function, ...) applied to class Foo, not to each member of Foo.
C++ is not introspective nor reflective, hence there is no way to do that according to the language spec. However, you can use Fusion to 'convert' your stucts to a fusion map or vector (depending on if you need names or not)
Is there such a convertor (struct->map) in http://www.boost.org/doc/libs/1_41_0/libs/fusion/doc/html/index.html ?
I am not familiar with boost::fusion.
Not a converter, it is an adapter, it lets you treat the struct as a fusion::map, but you still have to define it, just an easy way of defining it though, then you can use your struct as any normal fusion::map: http://www.boost.org/doc/libs/1_41_0/libs/fusion/doc/html/fusion/adapted/ada...