Boost logo

Boost :

From: Rani Sharoni (rani_sharoni_at_[hidden])
Date: 2003-01-30 09:34:44


"Gennaro Prota" <gennaro_prota_at_[hidden]> wrote in message
news:s18i3vorccgs6tmju273jl75b2bc896gl5_at_4ax.com...
> On Thu, 30 Jan 2003 12:38:36 -0000, "John Maddock"
> <jm_at_[hidden]> 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)
    };
};

struct B {};
struct B1 : B {};
struct B2 : B {};
struct D : B1, private B2 {};

struct BV1 : virtual B {};
struct BV2 : virtual B {};
struct DV : BV1, BV2 {};

typedef char TestA[is_base_and_derived<B, D>::result ? 1 : -1]; // Multiple
bases
typedef char TestB[is_base_and_derived<B1,D>::result ? 1 : -1];
typedef char TestC[is_base_and_derived<B2,D>::result ? 1 : -1]; // Private
base
typedef char TestD[!is_base_and_derived<int,D>::result ? 1 : -1];
typedef char TestF[is_base_and_derived<B,DV>::result ? 1 : -1]; // Virtual
base
// VC6/7 BUG.
// typedef char Test[!is_base_and_derived<D,D>::result ? 1 : -1];

Cheers,
Rani


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