mirror icon indicating copy to clipboard operation
mirror copied to clipboard

class generation?

Open pylaterreur opened this issue 11 years ago • 2 comments

Hi, I know the lib is in early stage of dev/reboot, but would it be possible to have some doc/example on class_generator, please? What I'd like to do would be to generate a class based on an existing one. I don't know if this is technically possible, I might be terribly wrong :) .

struct Existing
{
  static void f()
  {
    // [...]
  }
};

// generate a class such as:
struct Generated
 /* well, it would be great to be able to do not only pure-copies,
but also modify those copies */
: Existing
{
  static void f()
  {
    /* [...], not asking for a copy of Existing::f's body, would do something different here,
such as starting a timer/logger, then calling Existing::f :) */
  }
};

Once again, I might be really wrong, I don't know how far metaprog can go, even std::tr2::bases tastes like magic to me.

pylaterreur avatar Dec 31 '13 10:12 pylaterreur

more detailed comment in Existing::f()

pylaterreur avatar Dec 31 '13 10:12 pylaterreur

Hi,

Generally something like this is possible but, right now there are several problems with doing this:

  1. The class registering is not implemented yet so you can't reflect the class members.

  2. The class generator can currently create only member typedefs or member variables, but not member functions. Although the member variables could have a function call operator, so you could generate a class with members behaving like functions to simulate this.

  3. Calling of Existing:: in a generic way, is also still unimplemented (this depends largely on 1))

I'm currently experimenting with various implementations of 1), in the previous implementation of Mirror the registering depended heavily on the preprocessor and some folks frowned on that, so I'm trying to come up with some consistent and user friendly way of registering that would use macros only where absolutely necessary.

matus-chochlik avatar Dec 31 '13 10:12 matus-chochlik