|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-12-10 13:51:02
"Rani Sharoni" <rani_sharoni_at_[hidden]> writes:
> 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 4.3.0.1 and VC7.1+ with
> boost 1.30.2):
In the interest of education and spreading good idiomatic MPL practice:
> #include "boost/type_traits/is_class.hpp"
> #include "boost/mpl/if.hpp"
>
> template<typename T>
> struct is_abstract_class
> {
> private:
> typedef typename boost::mpl::if_c<boost::is_class<T>::value, T,
> int>::type TT;
typedef typename boost::mpl::if_<boost::is_class<T>, T, int>::type TT;
> typedef char (&yes)[1];
> typedef char (&no) [2];
>
> //
> // Deduction fails if U is void, function type, reference type
> (14.8.2/2)
> // or an abstract class type and according to WP issue #337
> // http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#337
> // supported by EDG3.0+ and VC7.1+
> //
> template<typename U>
> static no check(U (*)[1]);
>
> template<typename U>
> static yes check(...);
>
> public:
> static const bool value = sizeof(check<TT>(0)) == sizeof(yes);
> };
>
> I didn't find the type_traits self contained alternative for mpl::if_c.
IMO, why bother? Those type_traits ice_whatever idioms are cumbersome
and we should eventually replace them with clean MPL idioms.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk