1 #ifndef BORROWED_PTR_DWA20020601_HPP
2 # define BORROWED_PTR_DWA20020601_HPP
3 // Copyright David Abrahams 2002.
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 # include <boost/config.hpp>
9 # include <boost/type.hpp>
10 # include <boost/mpl/if.hpp>
11 # include <boost/type_traits/object_traits.hpp>
12 # include <boost/type_traits/cv_traits.hpp>
13 # include <boost/python/tag.hpp>
15 namespace boost { namespace python { namespace detail {
17 template<class T> class borrowed
22 # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
24 struct is_borrowed_ptr
26 BOOST_STATIC_CONSTANT(bool, value = false);
29 # if !defined(__MWERKS__) || __MWERKS__ > 0x3000
31 struct is_borrowed_ptr<borrowed<T>*>
33 BOOST_STATIC_CONSTANT(bool, value = true);
37 struct is_borrowed_ptr<borrowed<T> const*>
39 BOOST_STATIC_CONSTANT(bool, value = true);
43 struct is_borrowed_ptr<borrowed<T> volatile*>
45 BOOST_STATIC_CONSTANT(bool, value = true);
49 struct is_borrowed_ptr<borrowed<T> const volatile*>
51 BOOST_STATIC_CONSTANT(bool, value = true);
57 BOOST_STATIC_CONSTANT(bool, value = false);
60 struct is_borrowed<borrowed<T> >
62 BOOST_STATIC_CONSTANT(bool, value = true);
65 struct is_borrowed_ptr<T*>
66 : is_borrowed<typename remove_cv<T>::type>
71 # else // no partial specialization
73 typedef char (&yes_borrowed_ptr_t)[1];
74 typedef char (&no_borrowed_ptr_t)[2];
76 no_borrowed_ptr_t is_borrowed_ptr_test(...);
84 is_borrowed_ptr_test1(boost::type<T>);
87 yes_borrowed_ptr_t is_borrowed_ptr_test(borrowed<T> const volatile*);
93 BOOST_STATIC_CONSTANT(
95 sizeof(detail::is_borrowed_ptr_test(is_borrowed_ptr_test1(boost::type<T>())))
96 == sizeof(detail::yes_borrowed_ptr_t)));
99 # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
104 inline T* get_managed_object(detail::borrowed<T> const volatile* p, tag_t)
109 }} // namespace boost::python::detail
111 #endif // #ifndef BORROWED_PTR_DWA20020601_HPP