#include "runtime_contains_if.hpp" #include #include #include struct base { virtual ~base(){} }; struct child1 : public base {}; struct child2 : public base {}; struct child3 : public base {}; struct child4 : public base {}; struct child5 : public base {}; struct child6 : public base {}; struct child7 : public base {}; struct child8 : public base {}; struct child_detector { base* base_; child_detector( base* b ) : base_( b ) {} template< typename Derived_ > bool operator()( Derived_* ) { return ( 0 != dynamic_cast< Derived_* >( base_ ) ); } }; template< typename special_types > bool type_is_special( base* b ) { return boost::mpl::runtime_contains_if< special_types >( child_detector(b) ); } int main() { std::vector children; children.push_back( new child1 ); children.push_back( new child2 ); children.push_back( new child3 ); children.push_back( new child4 ); children.push_back( new child5 ); children.push_back( new child6 ); children.push_back( new child7 ); children.push_back( new child8 ); typedef boost::mpl::list< child1, child3, child7 > special_types; for( std::vector::size_type i = 0; i < children.size(); i++ ) { std::cout << type_is_special< special_types >( children[i] ) << std::endl; } return 0; }