
On Sun, 2009-01-04 at 22:53 +0100, Michiel Helvensteijn wrote:
I would like something like this (how I think it might look):
CLASS(Foo, FROM(Bar)) CONSTRUCT() CONSTRUCT(PAR(int, a, A), PAR(bool, b, B)) int A; bool B; END_CLASS
to automatically become something like this:
class Foo : public Bar, public shared_from_this<Foo> { private: Foo() {} public: static shared_ptr<Foo> construct() { return shared_ptr<Foo>(new Foo()); } private: Foo(int a, bool b) : A(a), B(b) {} public: static shared_ptr<Foo> construct(int a, bool b) { return shared_ptr<Foo>(new Foo(a, b)); } int A; bool B; };
Have you considered how boost::tuple might help ? A boost::tuple<int,bool> would seem to provide most of the above. A simple template could provide a tuple-wrapping class restricting allocation to the shared_ptr--returning construct method. OK so you wouldn't get to name the members, and the construct method itself would presumably need to take a tuple (unless you provide sufficient templated member functions to handle as many arguments as necessary). I don't know how important those aspects are to you though. In my experience, trying to be too clever with the preprocessor results in a nastier mess than the problem you were originally trying to solve. Tim