|
Boost : |
From: Rani Sharoni (rani_sharoni_at_[hidden])
Date: 2003-01-31 18:21:58
"Peter Dimov" <pdimov_at_[hidden]> wrote in message
news:007001c2c78e$ca921550$1d00a8c0_at_pdimov2...
> From: "Rani Sharoni" <rani_sharoni_at_[hidden]>
> >
> > I fogot to show little usability sample:
> >
> > struct B {};
> > struct B1 : B {};
> > struct B2 : B {};
> > struct D : B1, private B2 {};
> >
> > typedef char Test[is_base_and_derived<B, D>::result]; // improvement 1 -
> > multiple base
> > typedef char Test[is_base_and_derived<B1,D>::result];
> > typedef char Test[is_base_and_derived<B2,D>::result]; // improvement 2 -
> > private base
> > typedef char Test[!is_base_and_derived<int,D>::result];
>
> Very clever. But I'm not sure whether this is what is_base_and_derived is
> supposed to check. It seems that many are using it as
> is_accessible_base_of_derived, is-a, or is_convertible<D*, B*>.
IMHO there is only positive improvement.
Private base:
The current implementation will cause compile time error in all cases.
The new implementation will be good when there is access in the context of
the usage:
template<typename T>
void f(T *) { /* use is_base_and_derived<B, T>::result to convert T to B
*/ }
class A : B { friend void f<>(A*); }
It can also be abused to get access using c-cast:
if_< is_base_and_derived<B, A>::result, /* (B*)aptr */ , /* ??? */ >
Multiple bases:
For the ambiguity improvement Ill just mention that Eric Niebler asked for
the is_com_ptr trait and I wanted to help him.
Rani
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk