"Rani Sharoni" <[EMAIL PROTECTED]> wrote in message
b16dqm$sh9$[EMAIL PROTECTED]">news:b16dqm$sh9$[EMAIL PROTECTED]...
>
> "David Abrahams" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > "John Maddock" <[EMAIL PROTECTED]> writes:
> > > Yes, a class is it's own superclass/subclass, but IMO not it's own
> > > base: so it is a bug in the implementation.
> >
> > I'd like to suggest changing the documentation to match the
> > implementation at this point.  I know of a few places where I have
> > relied on the current semantics, and I'm sure that's the case for
> > others as well.  I'm not set on this course, but I think it's worth
> > considering.
>
> Before changing the documentation please consider the following improved
> implemetation that overcomes ambiguity and access control issues of the
> current is_base_and_derived implemetation (I lately posted it to
c.l.c++.m)
> :
>
> template <typename B, typename D>
> struct is_base_and_derived
> {
> private:
>     typedef char (&yes)[1];
>     typedef char (&no) [2];
>
>     template<typename T>
>     static yes check(D const volatile &, T);
>     static no  check(B const volatile &, int);
>
>     struct C
>     {
>         operator B const volatile &() const;
>         operator D const volatile &();
>     };
>
>     static C getC();
> public:
>     static const bool result =
>         sizeof(check(getC(), 0)) == sizeof(yes);
> };
>
> Additional specializations needed (e.g. void and reference types)

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];

Enjoy,
Rani




_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to