pointer_type_id.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 POINTER_TYPE_ID_DWA2002222_HPP
  6. # define POINTER_TYPE_ID_DWA2002222_HPP
  7. # include <boost/python/type_id.hpp>
  8. # include <boost/python/detail/type_traits.hpp>
  9. namespace boost { namespace python { namespace converter {
  10. namespace detail
  11. {
  12. template <bool is_ref = false>
  13. struct pointer_typeid_select
  14. {
  15. template <class T>
  16. static inline type_info execute(T*(*)() = 0)
  17. {
  18. return type_id<T>();
  19. }
  20. };
  21. template <>
  22. struct pointer_typeid_select<true>
  23. {
  24. template <class T>
  25. static inline type_info execute(T* const volatile&(*)() = 0)
  26. {
  27. return type_id<T>();
  28. }
  29. template <class T>
  30. static inline type_info execute(T*volatile&(*)() = 0)
  31. {
  32. return type_id<T>();
  33. }
  34. template <class T>
  35. static inline type_info execute(T*const&(*)() = 0)
  36. {
  37. return type_id<T>();
  38. }
  39. template <class T>
  40. static inline type_info execute(T*&(*)() = 0)
  41. {
  42. return type_id<T>();
  43. }
  44. };
  45. }
  46. // Usage: pointer_type_id<T>()
  47. //
  48. // Returns a type_info associated with the type pointed
  49. // to by T, which may be a pointer or a reference to a pointer.
  50. template <class T>
  51. type_info pointer_type_id(T(*)() = 0)
  52. {
  53. return detail::pointer_typeid_select<
  54. boost::python::detail::is_lvalue_reference<T>::value
  55. >::execute((T(*)())0);
  56. }
  57. }}} // namespace boost::python::converter
  58. #endif // POINTER_TYPE_ID_DWA2002222_HPP