fix doc example typo
[boost.git] / boost / python / ptr.hpp
blobaf1339c426443119d9edcf2b3148d559f7586ced
1 #ifndef PTR_DWA20020601_HPP
2 # define PTR_DWA20020601_HPP
4 # include <boost/python/detail/prefix.hpp>
5 // Copyright David Abrahams 2002.
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 //
10 // Based on boost/ref.hpp, thus:
11 // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
12 // Copyright (C) 2001 Peter Dimov
14 # if _MSC_VER+0 >= 1020
15 # pragma once
16 # endif
18 # include <boost/config.hpp>
19 # include <boost/mpl/bool.hpp>
21 namespace boost { namespace python {
23 template<class Ptr> class pointer_wrapper
25 public:
26 typedef Ptr type;
28 explicit pointer_wrapper(Ptr x): p_(x) {}
29 operator Ptr() const { return p_; }
30 Ptr get() const { return p_; }
31 private:
32 Ptr p_;
35 template<class T>
36 inline pointer_wrapper<T> ptr(T t)
38 return pointer_wrapper<T>(t);
41 # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
42 template<typename T>
43 class is_pointer_wrapper
44 : public mpl::false_
48 template<typename T>
49 class is_pointer_wrapper<pointer_wrapper<T> >
50 : public mpl::true_
54 template<typename T>
55 class unwrap_pointer
57 public:
58 typedef T type;
61 template<typename T>
62 class unwrap_pointer<pointer_wrapper<T> >
64 public:
65 typedef T type;
67 # else // no partial specialization
69 }} // namespace boost::python
71 #include <boost/type.hpp>
73 namespace boost { namespace python {
75 namespace detail
77 typedef char (&yes_pointer_wrapper_t)[1];
78 typedef char (&no_pointer_wrapper_t)[2];
80 no_pointer_wrapper_t is_pointer_wrapper_test(...);
82 template<typename T>
83 yes_pointer_wrapper_t is_pointer_wrapper_test(boost::type< pointer_wrapper<T> >);
85 template<bool wrapped>
86 struct pointer_unwrapper
88 template <class T>
89 struct apply
91 typedef T type;
95 template<>
96 struct pointer_unwrapper<true>
98 template <class T>
99 struct apply
101 typedef typename T::type type;
106 template<typename T>
107 class is_pointer_wrapper
109 public:
110 BOOST_STATIC_CONSTANT(
111 bool, value = (
112 sizeof(detail::is_pointer_wrapper_test(boost::type<T>()))
113 == sizeof(detail::yes_pointer_wrapper_t)));
114 typedef mpl::bool_<value> type;
117 template <typename T>
118 class unwrap_pointer
119 : public detail::pointer_unwrapper<
120 is_pointer_wrapper<T>::value
121 >::template apply<T>
124 # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
126 }} // namespace boost::python
128 #endif // #ifndef PTR_DWA20020601_HPP