>"Daniel Frey" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... >Rani Sharoni wrote: >> >> In the same fashion - I think that if type is not cv void, not reference and >> not convertible to bool (via standard conversion) then it's class type.
>Hm, could you show an implementation? [...] Sure. // // Please implement using boost facilities // is_reference, is_void, yes_type, no_type // and BOOST_STATIC_ASSERT // template<typename T> struct is_class { private: typedef char (&yes)[1]; typedef char (&no) [2]; struct boolcvt { boolcvt(bool); }; static no check(boolcvt); static yes check(...); static T& getT(); public: static const bool result = sizeof(check(getT())) == sizeof(yes); }; template<typename T> struct is_class<T&> { static const bool result = false; }; // add cv void versions template<> struct is_class<void> { static const bool result = false; }; // needed ? (EDG doesn't but VC7.1 does) template<typename T> struct is_class<T[]> { static const bool result = false; }; struct A { operator bool(); }; union U {}; enum E {}; typedef int test[is_class<A>::result]; typedef int test[is_class<U>::result]; typedef int test[not is_class<E>::result]; typedef int test[not is_class<A(int,A)>::result]; typedef int test[not is_class<A&>::result]; typedef int test[not is_class<A[]>::result]; void f() { struct pitfall {}; // is_class<pitfall>::result; } worked with VC7.1 and Comeau C/C++ 4.3.0.1 >> It might be useful implementation for compliers on which the SFIAE technique >> to detect class type doesn't work. >What is SFIAE? [...] I'm sorry, it should be SFINAE - substitution failure is not an error (but elimination of function template or partial specialization from candidate set). > template< typename > no_type test( ... ); > template< typename T > yes_type test( void (T::*)() ); > stuff from Paul Mensonides? Exactly. Enjoy, Rani _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost