
"Jody Hagins" <jody-boost-011304@atdesk.com> wrote in message news:20041206153207.0dd11478.jody-boost-011304@atdesk.com...
On Sat, 4 Dec 2004 23:44:46 -0700 "Jonathan Turkanis" <technews@kangaroologic.com> wrote:
You don't need typeid -- you can just do:
template<typename T> struct unique_id_holder { static char val; };
template<typename T> char unique_id_holder::val;
template<typename T> int unique_id() { return reinterpret_cast<int>(&unique_id_holder::val); }
For "better" portability, you should make that "int" a "long."
True. Daryle mentioned the problems about the size of integral types, and I was taking it for granted. The reason it doesn't matter much is that the applications which could benifit from a compile-time type id could do just as well if the id were split into several components.
Specifically, each of the above will get a different ID when calling unique_id<T>() with modifiers and references, but they will get the "same" std::type_info for those calls.
Yes, good point. It would be nice, for several purposes, if typeid were less forgetful. Jonathan