77// to its suitability for any purpose.
88
99# include < boost/config.hpp>
10- #include < boost/type.hpp>
10+ # include < boost/type.hpp>
11+ # include < boost/mpl/select_type.hpp>
12+ # include < boost/type_traits/object_traits.hpp>
13+ # include < boost/type_traits/cv_traits.hpp>
1114
1215namespace boost { namespace python { namespace detail {
1316
@@ -23,6 +26,7 @@ struct is_borrowed_ptr
2326 BOOST_STATIC_CONSTANT (bool , value = false );
2427};
2528
29+ # if !defined(__MWERKS__) || __MWERKS__ > 0x3000
2630template <typename T>
2731struct is_borrowed_ptr <borrowed<T>*>
2832{
@@ -46,24 +50,49 @@ struct is_borrowed_ptr<borrowed<T> const volatile*>
4650{
4751 BOOST_STATIC_CONSTANT (bool , value = true );
4852};
53+ # else
54+ template <typename T>
55+ struct is_borrowed
56+ {
57+ BOOST_STATIC_CONSTANT (bool , value = false );
58+ };
59+ template <typename T>
60+ struct is_borrowed <borrowed<T> >
61+ {
62+ BOOST_STATIC_CONSTANT (bool , value = true );
63+ };
64+ template <typename T>
65+ struct is_borrowed_ptr <T*>
66+ : is_borrowed<typename remove_cv<T>::type>
67+ {
68+ };
69+ # endif
4970
5071# else // no partial specialization
5172
5273typedef char (&yes_borrowed_ptr_t )[1];
5374typedef char (&no_borrowed_ptr_t )[2];
54-
75+
5576no_borrowed_ptr_t is_borrowed_ptr_test (...);
5677
78+ template <class T >
79+ typename mpl::select_type<
80+ is_pointer<T>::value
81+ , T
82+ , int
83+ >::type
84+ is_borrowed_ptr_test1 (boost::type<T>);
85+
5786template <typename T>
58- yes_borrowed_ptr_t is_borrowed_ptr_test (boost::type< borrowed<T>* > );
87+ yes_borrowed_ptr_t is_borrowed_ptr_test (borrowed<T> const volatile * );
5988
6089template <typename T>
6190class is_borrowed_ptr
6291{
6392 public:
6493 BOOST_STATIC_CONSTANT (
6594 bool , value = (
66- sizeof (detail::is_borrowed_ptr_test(boost::type<T>()))
95+ sizeof (detail::is_borrowed_ptr_test(is_borrowed_ptr_test1( boost::type<T>() )))
6796 == sizeof (detail::yes_borrowed_ptr_t )));
6897};
6998
0 commit comments