David Abrahams writes:
Aleksey Gurtovoy
writes: I think you can see why I'd like a type list iterator solution to this.
Try this:
struct do_something { do_something( BASE* base ) : m_base( base ) {}
template< typename T > void operator()( mpl::identity<T> ) const { if ( T* x = dynamic_cast< T* >( this->m_base ) ) some_function( x ); }
BASE* m_base; };
mpl::for_each< mpl::vector , mpl::make_identity<_1> >( do_something( base ) );
In this case you test for all the derived types, even if you match the first one, so it's not identical.
Yes, I should have mentioned it. You can always throw an exception after finding the match, but...
It would probably be nice of us to create a for_each_if() or until() function that stops when the function object returns true.
... I agree. -- Aleksey Gurtovoy MetaCommunications Engineering