Skip to content

Commit e2d75c0

Browse files
committed
Fixed is_borrowed_ptr
[SVN r14174]
1 parent 8aba486 commit e2d75c0

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

include/boost/python/detail/borrowed_ptr.hpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
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

1215
namespace 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
2630
template<typename T>
2731
struct 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

5273
typedef char (&yes_borrowed_ptr_t)[1];
5374
typedef char (&no_borrowed_ptr_t)[2];
54-
75+
5576
no_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+
5786
template<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

6089
template<typename T>
6190
class 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

test/borrowed.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// copyright notice appears in all copies. This software is provided
44
// "as is" without express or implied warranty, and with no claim as
55
// to its suitability for any purpose.
6+
#include <boost/python/detail/wrap_python.hpp>
67
#include <boost/python/borrowed.hpp>
78
#include <boost/static_assert.hpp>
89

0 commit comments

Comments
 (0)