|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-12-12 10:15:41
From: "David Abrahams" <david.abrahams_at_[hidden]>
> Today I discovered (to my horror) that the following are all supposed to
be
> identical:
>
> typeid(X)
> typeid(X const)
> typeid(X volatile)
> typeid(X const volatile)
> typeid(X&)
> typeid(X const&)
> typeid(X volatile&)
> typeid(X const volatile&)
>
> This happened when one of my compilers turned out to be conforming in this
> regard, and after spending quite a while trying to track the "bug" down, I
> bothered to look in the standard
> ;-)
>
> Since I needed all of the information to be there at runtime, I
implemented
> my own function
>
> template <class T>
> type_id_t type_id();
>
> which returns a unique type_id_t value for every T.
template<class T> struct typeid_helper
{
static int i;
};
template<class T> int typeid_helper<T>::i;
template<class T> void const * type_id()
{
return &typeid_helper<T>::i;
}
This doesn't work across DLLs, though. typeid() sometimes does.
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk