1 | #ifndef OTHER_DWA20020601_HPP |
---|
2 | # define OTHER_DWA20020601_HPP |
---|
3 | |
---|
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 | # if _MSC_VER+0 >= 1020 |
---|
11 | # pragma once |
---|
12 | # endif |
---|
13 | |
---|
14 | # include <boost/config.hpp> |
---|
15 | |
---|
16 | namespace boost { namespace python { |
---|
17 | |
---|
18 | template<class T> struct other |
---|
19 | { |
---|
20 | typedef T type; |
---|
21 | }; |
---|
22 | |
---|
23 | # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
---|
24 | namespace detail |
---|
25 | { |
---|
26 | template<typename T> |
---|
27 | class is_other |
---|
28 | { |
---|
29 | public: |
---|
30 | BOOST_STATIC_CONSTANT(bool, value = false); |
---|
31 | }; |
---|
32 | |
---|
33 | template<typename T> |
---|
34 | class is_other<other<T> > |
---|
35 | { |
---|
36 | public: |
---|
37 | BOOST_STATIC_CONSTANT(bool, value = true); |
---|
38 | }; |
---|
39 | |
---|
40 | template<typename T> |
---|
41 | class unwrap_other |
---|
42 | { |
---|
43 | public: |
---|
44 | typedef T type; |
---|
45 | }; |
---|
46 | |
---|
47 | template<typename T> |
---|
48 | class unwrap_other<other<T> > |
---|
49 | { |
---|
50 | public: |
---|
51 | typedef T type; |
---|
52 | }; |
---|
53 | } |
---|
54 | # else // no partial specialization |
---|
55 | |
---|
56 | }} // namespace boost::python |
---|
57 | |
---|
58 | #include <boost/type.hpp> |
---|
59 | |
---|
60 | namespace boost { namespace python { |
---|
61 | |
---|
62 | namespace detail |
---|
63 | { |
---|
64 | typedef char (&yes_other_t)[1]; |
---|
65 | typedef char (&no_other_t)[2]; |
---|
66 | |
---|
67 | no_other_t is_other_test(...); |
---|
68 | |
---|
69 | template<typename T> |
---|
70 | yes_other_t is_other_test(type< other<T> >); |
---|
71 | |
---|
72 | template<bool wrapped> |
---|
73 | struct other_unwrapper |
---|
74 | { |
---|
75 | template <class T> |
---|
76 | struct apply |
---|
77 | { |
---|
78 | typedef T type; |
---|
79 | }; |
---|
80 | }; |
---|
81 | |
---|
82 | template<> |
---|
83 | struct other_unwrapper<true> |
---|
84 | { |
---|
85 | template <class T> |
---|
86 | struct apply |
---|
87 | { |
---|
88 | typedef typename T::type type; |
---|
89 | }; |
---|
90 | }; |
---|
91 | |
---|
92 | template<typename T> |
---|
93 | class is_other |
---|
94 | { |
---|
95 | public: |
---|
96 | BOOST_STATIC_CONSTANT( |
---|
97 | bool, value = ( |
---|
98 | sizeof(detail::is_other_test(type<T>())) |
---|
99 | == sizeof(detail::yes_other_t))); |
---|
100 | }; |
---|
101 | |
---|
102 | template <typename T> |
---|
103 | class unwrap_other |
---|
104 | : public detail::other_unwrapper< |
---|
105 | is_other<T>::value |
---|
106 | >::template apply<T> |
---|
107 | {}; |
---|
108 | } |
---|
109 | |
---|
110 | # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
---|
111 | |
---|
112 | }} // namespace boost::python |
---|
113 | |
---|
114 | #endif // #ifndef OTHER_DWA20020601_HPP |
---|