Boost logo

Boost :

From: Rani Sharoni (rani_sharoni_at_[hidden])
Date: 2003-12-10 04:55:57

Jonathan Turkanis wrote:
> This is a small point, since the code in question is hidden with '#if
> 0'; however, there seem to be several typos in the definition of
> is_abstract.
I posted possible implementation for this important trait (and bother Jason
Shirk to implement it in VC7.1) while ago and wondered where can I see the
one that you are referring to?

Anyway, I simplify my original proposal some time ago and you might want to
consider the new implementation (tested using Comeau and VC7.1+ with
boost 1.30.2):

#include "boost/type_traits/is_class.hpp"
#include "boost/mpl/if.hpp"

template<typename T>
struct is_abstract_class
    typedef typename boost::mpl::if_c<boost::is_class<T>::value, T,
int>::type TT;

    typedef char (&yes)[1];
    typedef char (&no) [2];

    // Deduction fails if U is void, function type, reference type
    // or an abstract class type and according to WP issue #337
    // supported by EDG3.0+ and VC7.1+
    template<typename U>
    static no check(U (*)[1]);

    template<typename U>
    static yes check(...);

    static const bool value = sizeof(check<TT>(0)) == sizeof(yes);

// tests
struct A { virtual ~A() = 0; };

typedef int Test[ is_abstract_class<A>::value];

struct B {};

typedef int Test[!is_abstract_class<B>::value];
typedef int Test[!is_abstract_class<int>::value];
typedef int Test[!is_abstract_class<int(char,double)>::value];
typedef int Test[!is_abstract_class<int&>::value];
typedef int Test[!is_abstract_class<void>::value];

I didn't find the type_traits self contained alternative for mpl::if_c.


Boost list run by bdawes at, gregod at, cpdaniel at, john at