Boost logo

Boost :

From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2007-10-22 04:12:33


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.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk