|
Boost : |
From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2000-06-14 17:12:17
Mark Rodgers <mark.rodgers_at_[hidden]> wrote:
> So then I just restored the original simple operators.hpp and
> wrote
>
> class myclass // lose the inheritance...
> {
> //...
> };
> // explicitly instantiate the operators I need.
> template class less_than_comparable<myclass>;
> template class equality_comparable<myclass>;
> template class incrementable<myclass>;
> template class decrementable<myclass>;
> template class addable<myclass,long>;
> template class subtractable<myclass,long>;
>
> Now everything is less complex, and I've got sizeof(myclass) back
> to 4 without relying on any compiler optimisations.
>
> Comments?
It's a nice approach! (in cases when it's applicable). I agree with Dave
that it must be described in the documentation.
One more situation when you still need the inheritance approach is when you
write a class template like boost::geometry2d::point:
template<class T1, class T2 = T1>
class point
: addable< point<T1, T2>
, subtractable< point<T1, T2>
> >
{
//...
};
--Alexy
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk