Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-10-23 08:49:17


Here's an implementation that works with Comeau C/C++ 4.3.0.1, Intel C++ 6.0
and, surprisingly, MSVC 6.5 (after getting rid of partial specialization, of
course; not shown here):

    #include "boost/static_assert.hpp"
    #include "boost/config.hpp"

    template< typename T, int >
    struct identity_if
    {
        typedef T type;
    };

    template< typename T >
    struct identity_if<T,0>
    {
    };

    template< typename T, typename = T>
    struct is_incomplete
    {
        BOOST_STATIC_CONSTANT(bool, value = true);
    };

    template< typename T >
    struct is_incomplete<
          T
        , typename identity_if< T, sizeof(T) >::type
>
    {
        BOOST_STATIC_CONSTANT(bool, value = false);
    };

    union U {};
    class C {};
    struct S {};

    union incomplete_U;
    class incomplete_C;
    struct incomplete_S;

    BOOST_STATIC_ASSERT(!is_incomplete<U>::value);
    BOOST_STATIC_ASSERT(!is_incomplete<C>::value);
    BOOST_STATIC_ASSERT(!is_incomplete<S>::value);
    BOOST_STATIC_ASSERT(!is_incomplete<int>::value);
    BOOST_STATIC_ASSERT(is_incomplete<incomplete_U>::value);
    BOOST_STATIC_ASSERT(is_incomplete<incomplete_C>::value);
    BOOST_STATIC_ASSERT(is_incomplete<incomplete_S>::value);

Aleksey


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