Boost logo

Boost :

From: Brad King (brad.king_at_[hidden])
Date: 2002-06-12 15:33:27

> The variant implementation relies on the ability to map concrete types
> to integers. My implementation uses the index_of TypeList algorithm, for
> instance.
> So, unless we'll come-up with some birlliant way to do this mapping
> differently, we will not be able to implement a variant whose list of
> legal (concrete) types is 'open'.

Here is an idea that might work:

template <typename T>
class TypeId
  static unsigned long GetId()
    { return reinterpret_cast<unsigned long>(&TypeId::Id); }
  static void Id() {}

// ...


The linker (dynamic or otherwise) should ensure that there is only one
copy of TypeId<foo>::Id in any executable in memory (I'm not 100% sure
about this, though). This address will be unique, and will hopefully be
the same for the whole program. Comments on portability?


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