|
| 1 | +// Copyright David Abrahams 2002. Permission to copy, use, |
| 2 | +// modify, sell and distribute this software is granted provided this |
| 3 | +// copyright notice appears in all copies. This software is provided |
| 4 | +// "as is" without express or implied warranty, and with no claim as |
| 5 | +// to its suitability for any purpose. |
| 6 | +#ifndef POINTER_TYPE_ID_DWA2002222_HPP |
| 7 | +# define POINTER_TYPE_ID_DWA2002222_HPP |
| 8 | + |
| 9 | +# include <boost/python/converter/type_id.hpp> |
| 10 | +# include <boost/type_traits/composite_traits.hpp> |
| 11 | + |
| 12 | +namespace boost { namespace python { namespace converter { |
| 13 | + |
| 14 | +namespace detail |
| 15 | +{ |
| 16 | + template <bool is_ref = false> |
| 17 | + struct pointer_typeid_select |
| 18 | + { |
| 19 | + template <class T> |
| 20 | + static inline undecorated_type_id_t execute(T*(*)() = 0) |
| 21 | + { |
| 22 | + return undecorated_type_id<T>(); |
| 23 | + } |
| 24 | + }; |
| 25 | + |
| 26 | + template <> |
| 27 | + struct pointer_typeid_select<true> |
| 28 | + { |
| 29 | + template <class T> |
| 30 | + static inline undecorated_type_id_t execute(T* const volatile&(*)() = 0) |
| 31 | + { |
| 32 | + return undecorated_type_id<T>(); |
| 33 | + } |
| 34 | + |
| 35 | + template <class T> |
| 36 | + static inline undecorated_type_id_t execute(T*volatile&(*)() = 0) |
| 37 | + { |
| 38 | + return undecorated_type_id<T>(); |
| 39 | + } |
| 40 | + |
| 41 | + template <class T> |
| 42 | + static inline undecorated_type_id_t execute(T*const&(*)() = 0) |
| 43 | + { |
| 44 | + return undecorated_type_id<T>(); |
| 45 | + } |
| 46 | + |
| 47 | + template <class T> |
| 48 | + static inline undecorated_type_id_t execute(T*&(*)() = 0) |
| 49 | + { |
| 50 | + return undecorated_type_id<T>(); |
| 51 | + } |
| 52 | + }; |
| 53 | +} |
| 54 | + |
| 55 | +// Usage: pointer_type_id<T>() |
| 56 | +// |
| 57 | +// Returns an undecorated_type_id_t associated with the type pointed |
| 58 | +// to by T, which may be a pointer or a reference to a pointer. |
| 59 | +template <class T> |
| 60 | +undecorated_type_id_t pointer_type_id(T(*)() = 0) |
| 61 | +{ |
| 62 | + return detail::pointer_typeid_select< |
| 63 | + is_reference<T>::value |
| 64 | + >::execute((T(*)())0); |
| 65 | +} |
| 66 | + |
| 67 | +}}} // namespace boost::python::converter |
| 68 | + |
| 69 | +#endif // POINTER_TYPE_ID_DWA2002222_HPP |
0 commit comments