Boost logo

Boost :

From: Rani Sharoni (rani_sharoni_at_[hidden])
Date: 2003-12-09 10:59:41


Hi,

I accidentally encounter some bug in EDG (latest) that is exploitable for
implementing is_incomplete. I personally despise this ODR rebel but I
suspect that some really like it.

Anyway, the bug (per 3.9/7) is that for some reason EDG doesn't *find* the
appropriate T * operator+(T *, ptrdiff_t) built-in operator (13.6/13) for
incomplete types T.
This bug just roared in my ears for abuse. I can explain the implementation
technique if anyone thinks it's above trivial.

template<typename T>
struct is_incomplete
{
private:
    typedef T*(&yes)[2];

    struct helper
    {
        typedef T*(&yes)[2];
        struct eat { eat(helper); };
        friend yes operator+(eat, double);
        operator T*() const;
    };

public:
    static bool const value = sizeof(helper() + 1) == sizeof(yes);
};

template<typename T>
struct is_incomplete<T&>
{
    static bool const value = false; // or is_incomplete<T>::value ???
};

// Test cases http://www.comeaucomputing.com/tryitout/

struct A;
typedef int test[is_incomplete<A>::value];
typedef int test[is_incomplete<A const>::value];
typedef int test[is_incomplete<A volatile>::value];
typedef int test[is_incomplete<A volatile const>::value];
typedef int test[is_incomplete<A[ ]>::value];
typedef int test[is_incomplete<A[2]>::value];
typedef int test[is_incomplete<void>::value];
typedef int test[is_incomplete<void const>::value];

typedef int test[!is_incomplete<int>::value];
typedef int test[!is_incomplete<int const>::value];
typedef int test[!is_incomplete<int volatile>::value];
typedef int test[!is_incomplete<int volatile const>::value];

struct B {};
typedef int test[!is_incomplete<B>::value];
typedef int test[!is_incomplete<B const>::value];
typedef int test[!is_incomplete<B volatile>::value];
typedef int test[!is_incomplete<B volatile const>::value];
typedef int test[ is_incomplete<B[ ]>::value];
typedef int test[!is_incomplete<B[2]>::value];

Enjoy,
Rani

These Boost Were Made For Walking


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