msvc_typeinfo.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright David Abrahams 2002.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef MSVC_TYPEINFO_DWA200222_HPP
  6. # define MSVC_TYPEINFO_DWA200222_HPP
  7. #include <typeinfo>
  8. #include <boost/type.hpp>
  9. //
  10. // Fix for icc's broken typeid() implementation which doesn't strip
  11. // decoration. This fix doesn't handle cv-qualified array types. It
  12. // could probably be done, but I haven't figured it out yet.
  13. //
  14. // Note: This file is badly named. It initially was MSVC specific, but was
  15. // extended to cover intel too. Now the old version of MSVC is no longer
  16. // supported, but the intel version is still supported.
  17. # if defined(BOOST_INTEL_CXX_VERSION) && BOOST_INTEL_CXX_VERSION <= 700
  18. namespace boost { namespace python { namespace detail {
  19. typedef std::type_info const& typeinfo;
  20. template <class T>
  21. static typeinfo typeid_nonref(T const volatile*) { return typeid(T); }
  22. template <class T>
  23. inline typeinfo typeid_ref_1(T&(*)())
  24. {
  25. return detail::typeid_nonref((T*)0);
  26. }
  27. // A non-reference
  28. template <class T>
  29. inline typeinfo typeid_ref(type<T>*, T&(*)(type<T>))
  30. {
  31. return detail::typeid_nonref((T*)0);
  32. }
  33. // A reference
  34. template <class T>
  35. inline typeinfo typeid_ref(type<T>*, ...)
  36. {
  37. return detail::typeid_ref_1((T(*)())0);
  38. }
  39. #if defined(BOOST_MSVC) || (defined(__BORLANDC__) && !defined(BOOST_DISABLE_WIN32))
  40. # define BOOST_PYTT_DECL __cdecl
  41. #else
  42. # define BOOST_PYTT_DECL /**/
  43. #endif
  44. template< typename T > T&(* is_ref_tester1(type<T>) )(type<T>) { return 0; }
  45. inline char BOOST_PYTT_DECL is_ref_tester1(...) { return 0; }
  46. template <class T>
  47. inline typeinfo msvc_typeid(boost::type<T>*)
  48. {
  49. return detail::typeid_ref(
  50. (boost::type<T>*)0, detail::is_ref_tester1(type<T>())
  51. );
  52. }
  53. template <>
  54. inline typeinfo msvc_typeid<void>(boost::type<void>*)
  55. {
  56. return typeid(void);
  57. }
  58. # ifndef NDEBUG
  59. inline typeinfo assert_array_typeid_compiles()
  60. {
  61. return msvc_typeid((boost::type<char const[3]>*)0)
  62. , msvc_typeid((boost::type<char[3]>*)0);
  63. }
  64. # endif
  65. }}} // namespace boost::python::detail
  66. # endif // BOOST_INTEL_CXX_VERSION
  67. #endif // MSVC_TYPEINFO_DWA200222_HPP