Boost logo

Boost Users :

From: Duane Murphy (duanemurphy_at_[hidden])
Date: 2005-10-04 16:38:20


How do I iterate over a type list and call a function? MPL?

I have a base class BASE that has several subclasses A, B, C that have
special capabilities, but no way to identify those capabilities aside
from the type.

I would like to determine if an object of type BASE is also of one of
the special subclasses:

ie
void f( BASE* base)
{
    if ( dynamic_cast< A* >( base ) != NULL )
    {
        some_function( dynamic_cast< A* >( base ) );
    }
    else if ( dynamic_cast< B* >( base ) != NULL )
    {
        some_function( dynamic_cast< B* >( base ) );
    }
    else if ( dynamic_cast< C* >( base ) != NULL )
    {
        some_function( dynamic_cast< C* >( base ) );
    }
}

I think you can see why I'd like a type list iterator solution to this.

I have arranged for the some_function to be a template as well to make
things easier.

What I am looking for is the equivalent of find_if() but for types and
done at run time. I looked over MPL, but MPL seems to apply at compile
time without a door to the run time world. :-)

Thanks for your helpful tips!

 ...Duane


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