Test object identity with shared_ptr_converter.
[luabind.git] / luabind / detail / has_get_pointer.hpp
blob8a001ddda45578c75f997281a79d1dc3a4bd3b9e
1 // Copyright (c) 2005 Daniel Wallin
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_HAS_GET_POINTER_051022_HPP
24 # define LUABIND_HAS_GET_POINTER_051022_HPP
26 # include <boost/type_traits/add_reference.hpp>
28 # ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
29 # include <memory>
30 # endif
32 namespace luabind { namespace detail {
34 namespace has_get_pointer_
37 struct any
39 template<class T> any(T const&);
42 struct no_overload_tag
43 {};
45 typedef char (&yes)[1];
46 typedef char (&no)[2];
48 no_overload_tag operator,(no_overload_tag, int);
51 // On compilers with ADL, we need these generic overloads in this
52 // namespace as well as in luabind::. Otherwise get_pointer(any)
53 // will be found before them.
55 # ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
57 template<class T>
58 T* get_pointer(T const volatile*);
60 template<class T>
61 T* get_pointer(std::auto_ptr<T> const&);
63 # endif
66 // On compilers that doesn't support ADL, the overload below has to
67 // live in luabind::.
69 # ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
70 }} // namespace detail::has_get_pointer_
71 # endif
73 detail::has_get_pointer_::no_overload_tag
74 get_pointer(detail::has_get_pointer_::any);
76 # ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
77 namespace detail { namespace has_get_pointer_
79 # endif
81 template<class T>
82 yes check(T const&);
83 no check(no_overload_tag);
85 template<class T>
86 struct impl
88 static typename boost::add_reference<T>::type x;
90 BOOST_STATIC_CONSTANT(bool,
91 value = sizeof(has_get_pointer_::check( (get_pointer(x),0) )) == 1
94 typedef boost::mpl::bool_<value> type;
97 } // namespace has_get_pointer_
99 template<class T>
100 struct has_get_pointer
101 : has_get_pointer_::impl<T>::type
104 }} // namespace luabind::detail
106 #endif // LUABIND_HAS_GET_POINTER_051022_HPP