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
41 typedef typename
boost::mpl::if_
<boost::is_const
<T
>
47 template<bool is_Reference
= false>
48 struct is_const_reference_helper
61 typename is_const_type
<T
>::type
is_const_reference_tester(T
&);
62 no_t
is_const_reference_tester(...);
65 struct is_const_reference_helper
<true>
74 value
= sizeof(is_const_reference_tester(getT())) == sizeof(yes_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
;
89 struct is_const_reference
91 enum { value
= false };
92 typedef boost::mpl::bool_
<value
> type
;
96 struct is_const_reference
<const T
&>
98 enum { value
= true };
99 typedef boost::mpl::bool_
<value
> type
;
106 struct is_nonconst_reference
110 value
= boost::is_reference
<T
>::value
&& !is_const_reference
<T
>::value
112 typedef boost::mpl::bool_
<value
> type
;
116 yes_t
is_const_pointer_helper(void(*)(const A
*));
117 no_t
is_const_pointer_helper(...);
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
;
127 yes_t
is_nonconst_pointer_helper(void(*)(A
*));
128 no_t
is_nonconst_pointer_helper(...);
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
;
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();
151 value = sizeof(is_constructable_from_helper<T>::check(getFrom())) == sizeof(yes_t)
156 struct is_const_member_function_helper
158 static no_t test(...);
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
176 value = sizeof(is_const_member_function_helper<T>::test(getU())) == sizeof(yes_t)
181 template<int v1
, int v2
>
184 enum { value
= (v1
>v2
)?v1
:v2
};
189 #endif // LUABIND_TYPETRAITS_HPP_INCLUDED