Test object identity with shared_ptr_converter.
[luabind.git] / luabind / detail / typetraits.hpp
blobf27934e98da5ef06b6dcffcf30e9b3b5185bb735
1 // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the "Software"),
5 // to deal in the Software without restriction, including without limitation
6 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 // and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
14 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
18 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
24 #ifndef LUABIND_TYPETRAITS_HPP_INCLUDED
25 #define LUABIND_TYPETRAITS_HPP_INCLUDED
27 #include <luabind/config.hpp>
28 #include <boost/mpl/if.hpp>
29 #include <boost/type_traits/is_reference.hpp>
30 #include <boost/type_traits/is_const.hpp>
31 #include <luabind/detail/primitives.hpp>
33 namespace luabind { namespace detail
36 #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
38 template<class T>
39 struct is_const_type
41 typedef typename boost::mpl::if_<boost::is_const<T>
42 , yes_t
43 , no_t
44 >::type type;
47 template<bool is_Reference = false>
48 struct is_const_reference_helper
50 template<class>
51 struct apply
53 enum
55 value = false
60 template<class T>
61 typename is_const_type<T>::type is_const_reference_tester(T&);
62 no_t is_const_reference_tester(...);
64 template<>
65 struct is_const_reference_helper<true>
67 template<class T>
68 struct apply
70 static T getT();
72 enum
74 value = sizeof(is_const_reference_tester(getT())) == sizeof(yes_t)
79 template<class T>
80 struct is_const_reference
81 : is_const_reference_helper<boost::is_reference<T>::value>::template apply<T>
83 typedef boost::mpl::bool_<value> type;
86 #else
88 template<class T>
89 struct is_const_reference
91 enum { value = false };
92 typedef boost::mpl::bool_<value> type;
95 template<class T>
96 struct is_const_reference<const T&>
98 enum { value = true };
99 typedef boost::mpl::bool_<value> type;
102 #endif
105 template<class T>
106 struct is_nonconst_reference
108 enum
110 value = boost::is_reference<T>::value && !is_const_reference<T>::value
112 typedef boost::mpl::bool_<value> type;
115 template<class A>
116 yes_t is_const_pointer_helper(void(*)(const A*));
117 no_t is_const_pointer_helper(...);
119 template<class T>
120 struct is_const_pointer
122 enum { value = sizeof(is_const_pointer_helper((void(*)(T))0)) == sizeof(yes_t) };
123 typedef boost::mpl::bool_<value> type;
126 template<class A>
127 yes_t is_nonconst_pointer_helper(void(*)(A*));
128 no_t is_nonconst_pointer_helper(...);
130 template<class T>
131 struct is_nonconst_pointer
133 enum { value = sizeof(is_nonconst_pointer_helper((void(*)(T))0)) == sizeof(yes_t) && !is_const_pointer<T>::value };
134 typedef boost::mpl::bool_<value> type;
137 template<class T>
138 struct is_constructable_from_helper
140 static yes_t check(const T&);
141 static no_t check(...);
144 template<class T, class From>
145 struct is_constructable_from
147 static From getFrom();
149 enum
151 value = sizeof(is_constructable_from_helper<T>::check(getFrom())) == sizeof(yes_t)
155 template<class T>
156 struct is_const_member_function_helper
158 static no_t test(...);
159 template<class R>
160 static yes_t test(R(T::*)() const);
161 template<class R, class A1>
162 static yes_t test(R(T::*)(A1) const);
163 template<class R, class A1, class A2>
164 static yes_t test(R(T::*)(A1,A2) const);
165 template<class R, class A1, class A2, class A3>
166 static yes_t test(R(T::*)(A1,A2,A3) const);
169 template<class T, class U>
170 struct is_const_member_function
172 static U getU();
174 enum
176 value = sizeof(is_const_member_function_helper<T>::test(getU())) == sizeof(yes_t)
181 template<int v1, int v2>
182 struct max_c
184 enum { value = (v1>v2)?v1:v2 };
189 #endif // LUABIND_TYPETRAITS_HPP_INCLUDED