"Rani Sharoni" <[EMAIL PROTECTED]> wrote in message
b1bd2p$i97$[EMAIL PROTECTED]">news:b1bd2p$i97$[EMAIL PROTECTED]...
>
> "Gennaro Prota" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > On Thu, 30 Jan 2003 12:38:36 -0000, "John Maddock"
> > <[EMAIL PROTECTED]> wrote:
> >
> > >Except it *doesn't work* !
> > >
> >
> > John, unfortunately I have to turn off my computer now. I had just
> > hacked up a version that seems to work with gcc, but I don't want to
> > post it before a better testing. I'll let you know in the morning.
>
> Maybe you had the following variation on Terje's code in mind.
>
> The following worked with GCC3.1/2, VC6/7/7.1 and Comeau 4.3.0.1:
>
>
> typedef char (&yes)[1];
> typedef char (&no) [2];
>
> template <typename B, typename D>
> struct helper
> {
>     template <typename T>
>     static yes check(D const volatile *, T);
>     static no  check(B const volatile *, int);
> };
>
> template<typename B, typename D>
> struct is_base_and_derived
> {
>     struct Host
>     {
>         operator B const volatile *() const;
>         operator D const volatile *();
>     };
>
>     enum { result =
>         sizeof(helper<B,D>::check(Host(), 0)) == sizeof(yes)
>     };
> };

Here is a weird (but working !) version:

template <typename B, typename D>
struct helper
{
    template <typename T>
    static yes check(int B::*, T);
    static no  check(int D::*, int);
};

// TODO: add cv-qualifiers to B and D

template<typename B, typename D>
struct is_base_and_derived
{
    struct Host
    {
        operator int D::*() const;
        operator int B::*();
    };

    enum { result =
        sizeof(helper<B,D>::check(Host(), 0)) == sizeof(yes)
    };
};

BTW: the relevant section in the C++ standard is 13.3.3.2/4/3 (especially
the foot note).

Cheers,
Rani



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

Reply via email to