Re: typeid operator

From: Jonathan Turkanis (technews_at_kangaroologic.com)
Date: 10/27/04


Date: Wed, 27 Oct 2004 13:55:18 -0600


"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:0LSfd.7263$Ae.1053@newsread1.dllstx09.us.to.verio.net...
> Andrew Koenig wrote:
> > "Marco Jez" <nessuno@nessuno.com> wrote in message
> > news:FORfd.214470$35.10108467@news4.tin.it...
> >
> >
> >>I would like to use the reference returned by typeid as key in a std::map.
> >>Is it safe to assume that typeid(T) (where T is a type name) will always
> >>return the same reference to the same type_info structure for a given T?
> >
> >
> > I don't see why you should be able to make that assumption.
>
> I think the Standard in 5.2.8 says that the lvalue is returned and that
> the lifetime of the object referred to by the lvalue is entire program.
> So, why should we be able to make that assumption? Or did you forget the
> 'not' as in "I don't see why you should _not_ be able..."?

Wouldn't it be legal -- but insane -- for an implementation to have several
type_info objects for a given type, each of which has lifetime equal to the
entire program, and for typeid to to select one at random each time typeid is
invoked?

Perhaps support for dynamic libraries might sometimes lead to the existence of
two typeid objects for the same type.

Jonathan



Relevant Pages

  • Re: Unhandled exception - How to turn off!
    ... linked e.g. via typeid() which yields a std::type_info. ... defined by the same standard, i.e. the stuff in namespace std isn't in any ... absolutely no mention of namespace std. ... needs to be part of the language, ...
    (microsoft.public.vc.language)
  • Re: typeid operator
    ... >> the lifetime of the object referred to by the lvalue is entire program. ... and for typeid to to select one at random each time typeid is ... string comparisons to work out whether two types are the same, ...
    (comp.lang.cpp)