|
Boost : |
From: Rani Sharoni (rani_sharoni_at_[hidden])
Date: 2003-01-30 08:11:05
"Daniel Frey" <daniel.frey_at_[hidden]> wrote in message
news:3E38E30B.F8B43FCB_at_aixigo.de...
> > > Compiler: GNU C++ version 3.2 20020927 (prerelease)
> I also tried the GCC 3.2.1, but without success. It compiles, but it
> gives the wrong results.
> > > Any ideas, or results from other compilers?
>AFAICS the Intel 7 works fine.
> > I was able to complie the attached code (with minor improvment) using
strict
> > Comeau and VC7.1 and boost 1.29.0.
> One point about the implementation: The getC()-function isn't necessary,
Silly me. It seems that I got used to that function.
The following complied with VC6, VC7, VC7.1 and Comeau:
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 Host
{
operator B const volatile *() const;
operator D const volatile *();
};
public:
enum { result = sizeof(check(Host(), 0)) == sizeof(yes) };
};
struct B {};
struct B1 : B {};
struct B2 : B {};
struct D : B1, private B2 {};
typedef char Test[is_base_and_derived<B, D>::result];
typedef char Test[is_base_and_derived<B1,D>::result];
typedef char Test[is_base_and_derived<B2,D>::result];
typedef char Test[!is_base_and_derived<int,D>::result];
// Caveat VC6/7 BUG -
// typedef char Test[!is_base_and_derived<D,D>::result];
I was able to complie the following code using GCC 3.1 which proves that GCC
knows the required rules:
template<typename T>
long *f(D*, T);
char *f(B*, int);
struct Host1 {
operator B*() const;
operator D*();
};
long *x1 = f(Host1(), 0);
template<typename T>
long *g(B2*, T);
char *g(B1*, int);
struct Host2 {
operator B1*() const;
operator B2*();
};
char *x2 = g(Host2(), 0);
BCC 5.6 selected the wrong function (x1) which proves that it disagree about
the basic rules.
Rani
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk