C++03 solutions
(See KerrekSB's answer for solutions using C++11 features)
You can use another layer of inheritance and CRTP to dispatch the calls to your processor:
template< typename TYPE, class ProcessorHolder >
struct processorDispatch : interface<TYPE> {
virtual void f( TYPE t ) override {
processor& p = static_cast<ProcessorHolder*>(this)->p; //CRTP --> explicit downcast
p.f(t);
}
};
And use it as
struct der: processorDispatch< type1,der >, processorDispatch< type2,der >, processorDispatch< type3,der > {
processor p;
//make f visible - either
using processorDispatch< type1,der >::f;
using processorDispatch< type2,der >::f;
using processorDispatch< type3,der >::f;
//or
template <typename TYPE>
void f(TYPE t) {
processorDispatch<TYPE, der>::f(t);
}
}
};
A take at Kerrek's non-CRTP-solution, but "C++11-free" vía base class chaining:
struct der_base {
processor p;
};
template <class TYPE, class Base = der_base>
struct der_t : Base, interface<TYPE> {
void f(TYPE t) { this->p.f(t); }
using Base::f;
};
template <class TYPE>
struct der_t<TYPE, der_base> : der_base, interface<TYPE> {
void f(TYPE t) { this->p.f(t); }
};
And then use
typedef der_t<type1, der_t<type2, der_t<type3> > > der;