boost_no_is_abstract.ipp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // (C) Copyright John Maddock and Dave Abrahams 2002.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/config for most recent version.
  6. // MACRO: BOOST_NO_IS_ABSTRACT
  7. // TITLE: is_abstract implementation technique
  8. // DESCRIPTION: Some compilers can't handle the code used for is_abstract even if they support SFINAE.
  9. namespace boost_no_is_abstract{
  10. #if defined(__CODEGEARC__)
  11. template<class T>
  12. struct is_abstract_test
  13. {
  14. enum{ value = __is_abstract(T) };
  15. };
  16. #else
  17. template<class T>
  18. struct is_abstract_test
  19. {
  20. // Deduction fails if T is void, function type,
  21. // reference type (14.8.2/2)or an abstract class type
  22. // according to review status issue #337
  23. //
  24. template<class U>
  25. static double check_sig(U (*)[1]);
  26. template<class U>
  27. static char check_sig(...);
  28. #ifdef __GNUC__
  29. enum{ s1 = sizeof(is_abstract_test<T>::template check_sig<T>(0)) };
  30. #else
  31. enum{ s1 = sizeof(check_sig<T>(0)) };
  32. #endif
  33. enum{ value = (s1 == sizeof(char)) };
  34. };
  35. #endif
  36. struct non_abstract{};
  37. struct abstract{ virtual void foo() = 0; };
  38. int test()
  39. {
  40. return static_cast<bool>(is_abstract_test<non_abstract>::value) == static_cast<bool>(is_abstract_test<abstract>::value);
  41. }
  42. }