Topic: RTTI clarifications
Author: "Richard Smith" <richard@ex-parrot.com>
Date: Wed, 28 Nov 2001 19:03:08 GMT Raw View
"Martin Aupperle" <Martin.Aupperle@quasar-gmbh.de> wrote in message
news:3bfd3f30.359919526@News.CIS.DFN.De...
> On Tue, 20 Nov 2001 05:04:36 GMT, "Roger Orr"
> <rogero@howzatt.demon.co.uk> wrote:
> >
> >The intention is that the operator==(), !=() and before() methods provide
> >ways to compare or collate type_info objects, which enables programs to
make
> >use of typeinfo.
> >Note there are absolutely no guarantees about _how_ the collating will be
> >implemented - there is no guarantee that typinfo information is the same
> >between two programs [or even two executions of the same program] merely
> >that _an_ ordering is provided.
> >
>
> Can you please give a scenario where one would make use of collation
> of type_info-objects? I never understood why there is a
> before-function.
So that you can put typeinfos into associative containers:
struct typeinfo_cmp
: public std::binary_function<std::typeinfo, std::typeinfo, bool>
{
bool opertor()(const std::typeinfo *a, const std::typeinfo *b)
{
return a && ( !b || a->before(*b) );
}
};
std::map<const std::typeinfo *, std::string, typeinfo_cmp> foo;
(or perhaps better, wrap const std::typeinfo * in your own class that
provides operator ==).
And why might you want to do this? Well, the logarithmic multimethod double
dispatcher in Modern C++ Design uses Loki's TypeInfo in this way.
--
Richard Smith
---
[ 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://www.research.att.com/~austern/csc/faq.html ]
Author: "Bill Wade" <wrwade@swbell.net>
Date: Thu, 29 Nov 2001 01:18:17 GMT Raw View
"Martin Aupperle" <Martin.Aupperle@quasar-gmbh.de> wrote
> Can you please give a scenario where one would make use of collation
> of type_info-objects? I never understood why there is a
> before-function.
Suppose, in debugging code, you wanted to print some type names. Typically
your code uses type_info::name. However, for selected classes you want to
print another name (for instance "string" instead of
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >").
You might create a map from type_info to your replacement name.
You use the before() function to implement the ordering required by map.
---
[ 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://www.research.att.com/~austern/csc/faq.html ]
Author: Martin.Aupperle@quasar-gmbh.de (Martin Aupperle)
Date: Mon, 26 Nov 2001 19:36:09 GMT Raw View
On Tue, 20 Nov 2001 05:04:36 GMT, "Roger Orr"
<rogero@howzatt.demon.co.uk> wrote:
>
>The intention is that the operator==(), !=() and before() methods provide
>ways to compare or collate type_info objects, which enables programs to make
>use of typeinfo.
>Note there are absolutely no guarantees about _how_ the collating will be
>implemented - there is no guarantee that typinfo information is the same
>between two programs [or even two executions of the same program] merely
>that _an_ ordering is provided.
>
Can you please give a scenario where one would make use of collation
of type_info-objects? I never understood why there is a
before-function.
Martin
------------------------------------------------
Martin Aupperle
MikeAlpha@NoSpam_csi.com
(remove NoSpam_)
------------------------------------------------
---
[ 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://www.research.att.com/~austern/csc/faq.html ]
Author: "Justin Randall" <logic@jrlogic.dyndns.org>
Date: Mon, 19 Nov 2001 21:37:31 GMT Raw View
This may be a FAQ, but is there any impetus to standardize on exactly what
type information is available at run time using type_info?
Currently, the "human readable" name() method returns different values on
different compilers. This makes name() useless if data gleaned from classes
is going to be even remotely portable.
Is this a shortcoming of the standard (says nothing beyond "it must return a
unique name") or are compilers improperly implementing RTTI?
Thanks
---
[ 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://www.research.att.com/~austern/csc/faq.html ]
Author: Ron Natalie <ron@sensor.com>
Date: Mon, 19 Nov 2001 22:07:10 GMT Raw View
Justin Randall wrote:
> Currently, the "human readable" name() method returns different values on
> different compilers. This makes name() useless if data gleaned from classes
> is going to be even remotely portable.
It's not meant to be portable. That's why it's "human" readable and not
"machine interpretable." I think the issue is that the standards people
didn't want the code to be forced to propagate the "source file" names
which may no longer be present in the compiled code (the source file type
to decoration procedure could be one way, for example).
Frankly, if I were writing a compiler, I'd keep it in the source code style
names, but I can understand why they didn't want to force that on the
implementations.
---
[ 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://www.research.att.com/~austern/csc/faq.html ]
Author: "Roger Orr" <rogero@howzatt.demon.co.uk>
Date: Tue, 20 Nov 2001 05:04:36 GMT Raw View
Justin Randall wrote in message
<3bf97923$0$14920@news.denver1.Level3.net>...
>This may be a FAQ, but is there any impetus to standardize on exactly what
>type information is available at run time using type_info?
The contents of type_info is defined in 18.5.1 [lib.type.info]
The intention is that the operator==(), !=() and before() methods provide
ways to compare or collate type_info objects, which enables programs to make
use of typeinfo.
Note there are absolutely no guarantees about _how_ the collating will be
implemented - there is no guarantee that typinfo information is the same
between two programs [or even two executions of the same program] merely
that _an_ ordering is provided.
>Currently, the "human readable" name() method returns different values on
>different compilers. This makes name() useless if data gleaned from classes
>is going to be even remotely portable.
The name() method is provided mostly for display only, typically for help
with debugging.
Can you give an example of what you're trying to do, and perhaps someone can
suggest a portable way to do it?
Regards,
Roger Orr
--
MVP in C++ at www.brainbench.com
---
[ 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://www.research.att.com/~austern/csc/faq.html ]