Subject: Re: [boost] Is there any interest in a library which solves C++ class reflection feature just like Java does?
From: Matus Chochlik (chochlik_at_[hidden])
Date: 2011-12-07 04:28:12
On Tue, Dec 6, 2011 at 2:37 PM, jinhua luo <ljh.home.king_at_[hidden]> wrote:
OK let me say this so you don't get me wrong: I welcome any
attempt to add reflection to C++, I would very much like to have
reflection in the C++ standard with the full support of the compiler,
and I don't care on whose design it is based.
What I care about is that it is done properly, i.e. that it is not tailored
for a specific goal ORM, Serialization, RPC, GUI geneation, parser generation,
whatever .. but that it would support all of these and much more.
It should provide as much meta-data as possible even if some of it
might not be obviously usable in some scenario (it might be in others), etc.
It also should be compile-time because then you can use it with all the
great meta-programming tools implemented in Boost and elsewhere.
If you have a solid compile-time foundation you can implement run-time
reflection even, dynamically loadable easily.
> I have a quick look at the Mirror reflection utilities, although no deep
> investigation, I have some opinions about it:
> a) complex reflection declaration syntax (e.g. to describe the prototype of
> some method, it needs to use macro per parameter, but in my way, it's more
> easier and native: you just need to copy and parse the prototype from the
> class definition)
The syntax is complex only if you need to specify all details manually.
There are however the quick-registering macros that simplify the
registering quite a lot.
> b) depends on C++11 features (as mentioned in the web site, It has been
> tested and is currently known to work with the gcc 4.5.1 and higher), but
> my way does not require new versions of C++ standards, so it supports VC7
> or higher, and all gcc versions.
C++11 is a standard now and Mirror (AFAICT) doesn't use anything gcc-specific.
I know that the release cycles for compilers are quite long, but I hope that
we'll get good if not full support for C++11 soon.
> c) the source codes of the Mirror reflection utilities is a bit huge and
> complex than my one: my reflection library has only 3 header files and 1
> source file, and the codes are about 1200 lines.
It is true that Mirror is a big library, but to do some basic things
you certainly don't need to include every header. Much of the source
code implements "higher-level" tools on top of the basic reflection.
There is still some mess in the header organization, but I want to
have all that fixed in future releases.