
Corrado Zoccolo wrote:
BTW, the idea of the hand made vtable born in the discussion with gpd. My first implementation used just one function ptr to encapsulate all the behaviour (with a signature to fit all the methods), and was substantially less efficient than the current solution.
Instead of a hand make vtable, why not this? struct impl_base { virtual void something(void*) = 0; }; template<typename T> struct impl { void something(void* p) { // do something useful } }; template<typename T> class poly { template<typename U> poly(const U& u) { new(&type_info) impl<U>; ... } typename boost::aligned_storage< sizeof(impl<T>), boost::alignment_of< impl<T> > >::type type_info; }; This simply assumes that all instances of impl have the same size and alignment.