I’m using VS2005 and the MS implementation of STL. However, the class type_info in is declared outside of “namespace std”. This creates some problems for third party libs that excepts to find a std::type_info. Why is this so, and is there any workaround? Here is a sample from the beginning of typeinfo:
class type_info {
...
};
_STD_BEGIN // = namespace std {
That’s interesting – the standard does say that (17.4.1.1. Library contents)
And clearly says that (5.2.8 Type identification)
Ans, of course, the descriptin of header
<typeinfo?>indicate the it should be in namespacestd(18.5 Type identification):So
type_infoshould be in thestdnamespace (and not outside of it). I guess that either this is a bug or there’s some large set of code (or small set of important code) that needs it outside of thestdnamespace. I’d have thought they’d use some preprocessor magic to make it so you could force it to be in thestdnamespace if desired (or the other way around – make it instdby default and allow a macro or something to force it to the global namespace).However, one additional wrinkle for
type_infois that it’s the result of thetypeidoperator (more precisely, something derived fromtype_infois the result), so there’s probably a tight dependency on what the compiler does for thetypeidoperator that the library needs to be in line with. So the fact thattype_infoisn’t in namespacestdis possibly due to what the compiler does withtypeidexpressions, and the library writers probably have little direct control over that (and I’d guess that’s one reason why there’s no preprocssor workaround for the problem). Someone who knows a lot more about how compilers work than I do would have to explain this better (or take it beyond speculation).But I think you’ll have to ask someone at Microsoft (or PJ Plauger/Dinkumware) for a real answer to “why”.