I noticed that reflection is one of the features that developers from other languages really miss in C ++. For some applications, I really can understand why! It's much easier to write things like IDE autocomplete if you have reflection. And of course, serialization APIs would be easier in the world if we had it.
On the other hand, one of the basic principles of C ++ is not to pay for what you are not using. It makes sense. This is what I love about C ++.
But it occurred to me that there could be a compromise. Why don't compilers add extensions to the std::type_info ? There was no overhead. The binary may be larger, but it can be a simple compiler to turn on / off and, to be honest, if you are really worried about saving space, you will probably turn off exceptions and RTTI.
Some people cite problems with templates, but the compiler happily generates std::type_info for template types already.
I can imagine a g ++ switch like -fenable-typeinfo-reflection , which can become very popular (and in major libraries like boost / Qt / etc, it can be easy to check the code that uses it, if any, and in in this case, the end user will benefit at no cost than switching the switch). I do not think this is unreasonable, as large portable libraries like this already depend on compiler extensions.
So why is this not so common? I guess I missed something, what are the technical issues with this?
EDIT: Only a few re-the bloat metrics:
I looked at a rather large Qt project (about 45,000 LoC) and measures the size of meta objects. I think this is a reasonable metric because the Qt moc system is a fairly comprehensive reflection system (types, functions, enumerations, members, and a few special Qt concepts, such as “properties”). There were 67 meta objects in total, therefore not a trivial amount, but nothing crazy , which added up to 5479 bytes . However, almost all of them were 32 bytes or less ( the largest of which was 1427 bytes ). Given that modern compilers produce binaries higher than 4K for even the simplest program, these numbers are not outrageous). Although I would like to see something like this in relation to STL , to see how it looks.