
"Daryle Walker" <darylew@hotmail.com> wrote in message news:BAY23-DAV2FA8157E525BDF2DA9F2BBFB30@phx.gbl...
On 12/3/04 4:59 PM, "Jonathan Turkanis" <technews@kangaroologic.com> wrote:
Attached is some non-conforming code which automatically assigns a unique integer id to an arbitrary type. It's based on this post by Daniel Wallin:
http://lists.boost.org/MailArchives/boost/msg69842.php [TRUNCATE]
I take that computing these IDs at compile-time is a requirement?
That's the idea. Fortunately it's not a requirement of anything, since it's not really possible ;-)
Otherwise you could use something like:
reinterpret_cast<unsigned>(static_cast<void const *>(&typeid(T)));
This assumes that a void-pointer can fit within an unsigned.
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); } Jonathan