boost_no_rtti.ipp 903 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // (C) Copyright John Maddock 2008.
  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_RTTI
  7. // TITLE: RTTI unavailable
  8. // DESCRIPTION: The compiler does not support RTTI in this mode
  9. #include <typeinfo>
  10. class A
  11. {
  12. public:
  13. A(){}
  14. virtual void t();
  15. };
  16. void A::t()
  17. {
  18. }
  19. class B : public A
  20. {
  21. public:
  22. B(){}
  23. virtual void t();
  24. };
  25. void B::t()
  26. {
  27. }
  28. namespace boost_no_rtti
  29. {
  30. int check_f(const A& a)
  31. {
  32. return typeid(a) == typeid(B) ? 0 : 1;
  33. }
  34. int test()
  35. {
  36. #if defined( BOOST_NO_EXCEPTIONS )
  37. {
  38. B b;
  39. return check_f(b);
  40. }
  41. #else
  42. try{
  43. B b;
  44. return check_f(b);
  45. }
  46. catch(...)
  47. {
  48. return 1;
  49. }
  50. #endif
  51. }
  52. }