From -1667602065283281409
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f635e,e7776fa3664990ff
X-Google-Attributes: gidf635e,public
X-Google-Thread: f78e5,5cc0e5689db82f7b
X-Google-Attributes: gidf78e5,public
From: hinnant@_anti-spam_lightlink.com (Howard Hinnant)
Subject: Re: Is type_info object static or temporary?
Date: 1998/06/02
Message-ID: <hinnant-0106982005000001@port44.lightlink.com>#1/1
X-Deja-AN: 358633015
X-NNTP-Posting-Host: 205.232.34.144
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <356D82DA.36025D97@matfys.lth.se> <6kl3ar$npi$1@shell7.ba.best.com> <35727d32.0@210.134.196.10>
X-UID: 0000000001
X-Status: $$$T
Organization: Lightlink Internet
Newsgroups: comp.std.c++,comp.sys.mac.programmer.codewarrior
Originator: clamage@taumet


In article <35727d32.0@210.134.196.10>, "HiroshiOda"
<HiroshiOda@root.or.jp> wrote:

> Why the class std::type_info is designed to be prevent copying?
> I read 'The C++ programing language 3rd edi.'. And in section 15.4.4, RTTI
> is described. I would like to use such a kind of map as map< type_info, ...
> >, so I've first created the helper class as followings.
> 
> class my_type_info {
> private :
>     const type_info* info ;
> public :
>     my_type_info() : info( 0 ) {}
>     my_type_info( const type_info& sorc ) : info( &sorc ) {}
>     my_type_info( const my_type_info& sorc ) : info( sorc.info ) {}
>     my_type_info& operator =( const my_type_info& sorc ) { info = sorc.info
> ;     
>     }
>     bool operator ==( const my_type_info& another ) {
>         return *info == *another.info ;
>     }
>     bool operator <( const my_type_info& another ) {
>         return info->before( *another.info ) ;
>     }
>     bool operator !=( .....
>     bool operator >( .....
>     .....
> } ;
> 
> Now map< my_type_info, ... > is well-defined. But I'm not sure which we may
> assume the return value of typeid() refers to something of temporary object
> or global static object. If it is temporary object, the design of the class
> my_type_info is bad. But Stroustrup's description of p.415 seems to say that
> type_info objects are global objects. Can we assume so? No example there
> bind the type_info object in any const references nor const pointers.
> 
> Secondly, for safety I decide to design my map to be the form map< const
> char*, ... > where const char* is a string pointer got by
> typeid(...).name(). This is just as Stroustrup's example. Here I assume that
> C-strings got by typeid(...).name() will never go. Again, can we assume so?
> 
> Thanks to your help.

I believe that your design is safe.  The standard says:

1 The result of a typeid expression is an lvalue of  static  type  const
  std::type_info (_lib.type.info_) and dynamic type const std::type_info
  or const name where name is an  implementation-defined  class  derived
  from   std::type_info   which  preserves  the  behavior  described  in
  _lib.type.info_.9) The lifetime of  the  object  referred  to  by  the
  lvalue extends to the end of the program.  Whether or not the destruc-
  tor is called for the type_info object at the end of  the  program  is
  unspecified.

The comment about the lifetime of the object, I believe, guarantees that
info will always be pointing to a valid type_info (as long as it starts
out that way).

-Howard


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




