Boost logo

Boost Users :

From: Iulian M (eti_at_[hidden])
Date: 2006-02-08 12:33:57


On Wednesday 08 February 2006 17:41, Rene Rivera wrote:
>
> There's no easy way for the boost.any code to work with polymorphic
> types as you expect since there's no current way to know what types are
> convertible at runtime. (Perhaps when there's a boost.reflect)
>

Actually you gave me the solution. It just happens that in my project there is
a type registry ( a registry where different objects register information
about their type, information including base types ) - not quite a complete
reflection system but has the info i need.
I'll have to use unsafe_any_cast witch i've seen that it's not in the public
interface of boost.any but i'll just have to live with it ( and hope it will
never change ).

it goes something like this

class A {}; //base calss
class B: public A {}; // derived class

int main()
{
    B *b = new B(); //create derived class
         boost::any n(b); // place inside boost::any

        if( TypeManager::type( n.type() )->findBaseClass(a))
        {
                A* a=unsafe_any_cast<A*>(n);
        } else throw ...
                
}

Thanks,
Iulian

-- 
I used to be an agnostic, but now I'm not so sure.



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