Boost logo

Boost :

From: Lin Xu (risingdragon3_at_[hidden])
Date: 2003-05-10 03:32:28


> template <class T, T v, char const*> struct member {};
> template <class T> struct members;
>
> template <>
> struct members<X>
> : mpl::vector<
> member<int(X::*)(double), &X::f, "f">
> , member<char*(X::*), &X::x, "x">
> , member<int&, X::y, "y">
> >
> {
> };
I realize that you were quickly drafting this code, but wouldn't you need to
define the names as const char*, and that the member tempalte should take a
member pointer?

The problem is that string constants have to be defined *outside* the
definition of the template, as I remember from discussion from a compile
time string class. But you can't really do much compile time manipulation of
strings, anyway. For starters, comparision (is_same) of template classes
with string constants (predictably) fail when you define two different const
char*'s that contain the same thing.
I think that the string name should be relegated to the runtime aspect of
reflection - unless, the only thing being supported is runtime reflection
(perhaps in conjunction with dynamic_any).
At compile time, the only way to give a member a unique identity is with
some sort of tag class, which later on can be used to get the value:

struct prop_x {};
...
struct y { int x };
//define the reflection
y test;
reflect<y>::get<prop_x>(test) = 10.4;

At runtime, of course, things are different. Something like this may be
possible:
template <> struct reflect<y> : public reflect_base<y> {
   MEMBER(x);
};

reflect<y>::bind_to(test)["x"] = 10;

Comments?

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk