Boost logo

Boost :

Subject: Re: [boost] [TypeIndex] Peer review period for library acceptance begins, ending Thurs 21st Nov
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2013-11-15 08:31:01


2013/11/15 Mathieu Champlon <m.champlon_at_[hidden]>

> Hi,
>
> Quickly skimming the documentation and code I'm just wondering what
> exactly would be the problem if I were to do :
>
> template <class T>
> const type_info& my_type_id( const T& ) {
> return type_info::construct<T>();
> }
>
> my_type_id( variable ) // instead of boost::type_id_rtti_only(variable)
>
> ?
>

type_info::construct<T>() works with the type T, while
boost::type_id_rtti_only(variable) attempts to determinate the real type of
variable. Here's an example:

class Base { virtual *~*Base(){} };
class Derived: public Base {};

...
Derived d;
Base& variable = d;

my_type_id( variable ).name_demangled(); // returns `Base`
boost::type_id_rtti_only(variable).name_demangled(); // returns `Derived `

-- 
Best regards,
Antony Polukhin

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk