Boost logo

Boost Users :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2001-11-08 23:25:27


On Thursday 08 November 2001 20:07, you wrote:
> Hi,
>
> any is really a powerful class, but sometimes I would also be
> able to know directly the type stored into it without 'guessing', for
> example to use it in template code.
> What I would like to have is something as
>
> type_info::real_type for the value hidden into any (not legal C++, maybe
> legal C++0x ?),
>
> or, alternatively, virtual template functions (again not legal C++) to be
> able to write generic
> code depending on both hidden value's type and types 'from the outside
> world' (sorry cannot explain it better :-( than this)
>
> I have tried various approaches, but if I 'visit' the any class adding a
> virtual function to reach hidden value I loose generic type information
> (lack of virtual template functions) from the outside while from the
> outside of any
> I cannot obtain directly the type of the hidden value ...
>
> is there a way to do the above ?

Short answer: no.

Asking for the type given only a type_info object is asking a runtime entity
(the object returned by typeid) to return a compile-time entity (a type). To
make a scheme such as this work for all types (without enumerating them)
would require all information about types to be resolved at compile time. At
that point, static checking of types within C++ becomes impossible, and C++
starts to feel like Smalltalk <shutters>.

        Doug


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net