Initial C++0x support.
[luabind.git] / luabind / value_wrapper.hpp
blob8e09395d5c3023d47b2e8a0540da2d1a920478b7
1 // Copyright (c) 2005 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.
23 #ifndef LUABIND_VALUE_WRAPPER_050419_HPP
24 #define LUABIND_VALUE_WRAPPER_050419_HPP
26 #include <boost/mpl/integral_c.hpp>
27 #include <boost/mpl/bool.hpp>
28 #include <boost/mpl/aux_/msvc_eti_base.hpp>
30 #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
31 # define LUABIND_USE_VALUE_WRAPPER_TAG
32 #else
33 #endif
35 #ifdef LUABIND_USE_VALUE_WRAPPER_TAG
36 # include <boost/mpl/identity.hpp>
37 # include <boost/mpl/eval_if.hpp>
38 # include <boost/mpl/has_xxx.hpp>
39 # include <boost/mpl/not.hpp>
40 # include <boost/mpl/and.hpp>
41 # include <boost/mpl/or.hpp>
42 # include <boost/type_traits/is_reference.hpp>
43 # include <boost/type_traits/is_pointer.hpp>
44 # include <boost/type_traits/is_array.hpp>
45 #endif
47 namespace luabind {
50 // Concept ``ValueWrapper``
53 #ifdef LUABIND_USE_VALUE_WRAPPER_TAG
54 template<class T>
55 struct value_wrapper_traits;
57 namespace detail
60 BOOST_MPL_HAS_XXX_TRAIT_DEF(value_wrapper_tag);
62 struct unspecialized_value_wrapper_traits
64 typedef boost::mpl::false_ is_specialized;
67 template<class T>
68 struct value_wrapper_traits_aux
70 typedef value_wrapper_traits<typename T::value_wrapper_tag> type;
73 } // namespace detail
74 #endif
76 template<class T>
77 struct value_wrapper_traits
78 #ifdef LUABIND_USE_VALUE_WRAPPER_TAG
79 : boost::mpl::eval_if<
80 boost::mpl::and_<
81 boost::mpl::not_<
82 boost::mpl::or_<
83 boost::is_reference<T>
84 , boost::is_pointer<T>
85 , boost::is_array<T>
88 , detail::has_value_wrapper_tag<T>
90 , detail::value_wrapper_traits_aux<T>
91 , boost::mpl::identity<detail::unspecialized_value_wrapper_traits>
92 >::type
93 {};
94 #else
96 typedef boost::mpl::false_ is_specialized;
98 #endif
100 template<class T>
101 struct is_value_wrapper
102 : boost::mpl::aux::msvc_eti_base<
103 typename value_wrapper_traits<T>::is_specialized
104 >::type
107 } // namespace luabind
109 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
111 # include <boost/type_traits/remove_const.hpp>
112 # include <boost/type_traits/remove_reference.hpp>
114 namespace luabind {
116 template<class T>
117 struct is_value_wrapper_arg
118 : is_value_wrapper<
119 typename boost::remove_const<
120 typename boost::remove_reference<T>::type
121 >::type
125 } // namespace luabind
127 #else
129 # include <luabind/detail/yes_no.hpp>
130 # include <boost/type_traits/add_reference.hpp>
132 namespace luabind {
134 namespace detail
136 template<class T>
137 typename is_value_wrapper<T>::type is_value_wrapper_arg_check(T const*);
139 yes_t to_yesno(boost::mpl::true_);
140 no_t to_yesno(boost::mpl::false_);
142 template<class T>
143 struct is_value_wrapper_arg_aux
145 static typename boost::add_reference<T>::type x;
147 BOOST_STATIC_CONSTANT(bool, value =
148 sizeof(to_yesno(is_value_wrapper_arg_check(&x)))
149 == sizeof(yes_t)
152 typedef boost::mpl::bool_<value> type;
155 } // namespace detail
157 template<class T>
158 struct is_value_wrapper_arg
159 : detail::is_value_wrapper_arg_aux<T>::type
163 } // namespace luabind
165 #endif
167 #endif // LUABIND_VALUE_WRAPPER_050419_HPP