Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-12-05 01:44:46

"Daryle Walker" <darylew_at_[hidden]> wrote in message
> On 12/3/04 4:59 PM, "Jonathan Turkanis" <technews_at_[hidden]> 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:
> >
> >
> 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);


Boost list run by bdawes at, gregod at, cpdaniel at, john at