1 // Copyright (c) 2005 Daniel Wallin 2 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: 9 10 // The above copyright notice and this permission notice shall be included 11 // in all copies or substantial portions of the Software. 12 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. 22 23 #ifndef LUABIND_HAS_GET_POINTER_051022_HPP 24 # define LUABIND_HAS_GET_POINTER_051022_HPP 25 26 # include <boost/type_traits/add_reference.hpp> 27 # include <boost/mpl/bool.hpp> 28 29 # ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP 30 # include <memory> 31 # endif 32 33 namespace luabind { namespace detail { 34 35 namespace has_get_pointer_ 36 { 37 38 struct any 39 { 40 template<class T> any(T const&); 41 }; 42 43 struct no_overload_tag 44 {}; 45 46 typedef char (&yes)[1]; 47 typedef char (&no)[2]; 48 49 no_overload_tag operator,(no_overload_tag, int); 50 51 // 52 // On compilers with ADL, we need these generic overloads in this 53 // namespace as well as in luabind::. Otherwise get_pointer(any) 54 // will be found before them. 55 // 56 # ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP 57 58 template<class T> 59 T* get_pointer(T const volatile*); 60 61 template<class T> 62 # ifdef LUABIND_USE_CXX11 63 T* get_pointer(std::unique_ptr<T> const&); 64 # else 65 T* get_pointer(std::auto_ptr<T> const&); 66 # endif 67 68 # endif 69 70 // 71 // On compilers that doesn't support ADL, the overload below has to 72 // live in luabind::. 73 // 74 # ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP 75 }} // namespace detail::has_get_pointer_ 76 # endif 77 78 detail::has_get_pointer_::no_overload_tag 79 get_pointer(detail::has_get_pointer_::any); 80 81 # ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP 82 namespace detail { namespace has_get_pointer_ 83 { 84 # endif 85 86 template<class T> 87 yes check(T const&); 88 no check(no_overload_tag); 89 90 template<class T> 91 struct impl 92 { 93 static typename boost::add_reference<T>::type x; 94 95 BOOST_STATIC_CONSTANT(bool, 96 value = sizeof(has_get_pointer_::check( (get_pointer(x),0) )) == 1 97 ); 98 99 typedef boost::mpl::bool_<value> type; 100 }; 101 102 } // namespace has_get_pointer_ 103 104 template<class T> 105 struct has_get_pointer 106 : has_get_pointer_::impl<T>::type 107 {}; 108 109 }} // namespace luabind::detail 110 111 #endif // LUABIND_HAS_GET_POINTER_051022_HPP 112