I'm currently going to write big project in c++11.
I'm searching for some time good c++11/c++ reflection library and I've found several different libraries, but most of them are simply not updated for last couple of years or their functionality is very limited.
Could you tell me if there is a really good library for c++1/c++ for reflection? (I want to have static and dynamic reflection, know as much information as I can about methods, classes etc, can dynamically add and access methods etc.)
Or maybe c++11 has provided some additional functionality that will help to better design reflection libraries and should I write it by myself? (I haven't found information about it though.)
C++ is not really the best language for reflection. C++0x doesn't really change that. You can get limited support for static reflection using type traits, and you can even use SFINAE to statically determine whether a certain class has a particular member function or member variable. But that's really it.
Dynamic reflection is severely limited. You can get the type of a class at runtime using the <typeinfo>
facilities, but that's about it.
As for static reflection, the ability to generically iterate over a class and get each member variable/function is just not possible without serious compromises. Boost.Fusion manages to pull this off by providing macros which allow you to bind an object to a tuple-like container. In fact, the std::tuple
or boost::tuple
class naturally provide compile-time reflection - in other words, you can statically iterate over a tuple and determine the type of each member. This gives you something approximating compile-time reflection over arbitrary aggregate types. Unfortunately, it's not as convenient as if there were native reflection support built in for arbitrary classes.