Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-02-10 00:16:01

"Lin Xu" <risingdragon3_at_[hidden]> writes:

> I've done some searching on the boost dev list archives, and I've seen
> some interest in a reflection system in C++. I've implemented a full
> reflection system - not only "properties" but functions as well - in
> compile time. There is no storage cost or runtime cost (on MSVC7, the
> assembly isntructions are the same - I haven't checked on
> others). It's also possible to implement runtime reflection too, but
> this would bring a runtime cost. I wish to implement compiletime
> first, then use that to build runtime.
> Mainly, I use templates to implement 'properties'. the syntax I would
> forsee is something like this:
> struct A {
> int z;
> int getz() const {return z;}
> void setz(int k) {z = k;}
> void print() {cout << z << endl;}
> };
> namespace Prop {
> struct val {};
> struct print {};
> struct val2 {};
> }
> template <> struct Reflect<A> {
> typedef Implements<
> Prop::val, GetSetPair<A,int,&A::getz,&A::setz>,
> Prop::print, Function<void>::MemberFun<A,&A::print>,
> //another way of accessing z, without get/setters:
> Prop::val2, Member<A,int,&A::z>,
> //read only (even could be write-only!)
> Prop::val3, GetSet<Getter<A,int,&A::getz> >
> };
> That's the basic sytnax. This *could* be done using an automated
> parser, but there's certain things that the system can do that if
> you do by hand, you can do.

But you can't do that ;-)

In particular, MemberFun<A,&A::print> is incompatible with, say,
MemberFun<A, &A::setz>. You'd need something more like:

  MemberFun<void(A::*)(), &A::print>
  MemberFun<void(A::*)(int), &A::setz>

Sad but true :(

Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at