diff --git a/include/boost/core/pointer_traits.hpp b/include/boost/core/pointer_traits.hpp index b604b58..ff1a532 100644 --- a/include/boost/core/pointer_traits.hpp +++ b/include/boost/core/pointer_traits.hpp @@ -24,7 +24,7 @@ namespace detail { template inline typename boost::pointer_traits::element_type* -ptr_traits_address(U v) BOOST_NOEXCEPT +ptr_traits_address(const U& v) BOOST_NOEXCEPT { return boost::pointer_traits::to_address(v); } @@ -40,7 +40,7 @@ struct pointer_traits typedef typename std::pointer_traits::template rebind type; }; static typename std::pointer_traits::element_type* - to_address(T v) BOOST_NOEXCEPT { + to_address(const T& v) BOOST_NOEXCEPT { return detail::ptr_traits_address(v.operator->()); } }; @@ -211,7 +211,7 @@ struct pointer_traits { pointer_to(typename detail::ptr_traits_value::type& v) { return pointer::pointer_to(v); } - static element_type* to_address(pointer v) BOOST_NOEXCEPT { + static element_type* to_address(const pointer& v) BOOST_NOEXCEPT { return detail::ptr_traits_address(v.operator->()); } }; diff --git a/test/to_address_test.cpp b/test/to_address_test.cpp index a4fdfd2..650d105 100644 --- a/test/to_address_test.cpp +++ b/test/to_address_test.cpp @@ -21,6 +21,44 @@ private: T value_; }; +template +class special { +public: + special(T* value) + : value_(value) { } + T* get() const BOOST_NOEXCEPT { + return value_; + } +private: + T* value_; +}; + +namespace boost { + +template +struct pointer_traits > { + typedef special pointer; + typedef T element_type; + typedef std::ptrdiff_t difference_type; + template + struct rebind_to { + typedef special type; + }; +#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) + template + using rebind = typename rebind_to::type; +#endif + template + static pointer pointer_to(U& v) BOOST_NOEXCEPT { + return pointer(&v); + } + static element_type* to_address(const pointer& v) BOOST_NOEXCEPT { + return v.get(); + } +}; + +} /* boost */ + int main() { int i = 0; @@ -59,5 +97,35 @@ int main() type p(&i); BOOST_TEST(boost::to_address(p) == &i); } + { + typedef special type; + type p(&i); + BOOST_TEST(boost::to_address(p) == &i); + } + { + typedef special type; + type p(&i); + BOOST_TEST(boost::to_address(p) == &i); + } + { + typedef special type; + type p(&i); + BOOST_TEST(boost::to_address(p) == &i); + } + { + typedef pointer > type; + type p(&i); + BOOST_TEST(boost::to_address(p) == &i); + } + { + typedef pointer > type; + type p(&i); + BOOST_TEST(boost::to_address(p) == &i); + } + { + typedef pointer > type; + type p(&i); + BOOST_TEST(boost::to_address(p) == &i); + } return boost::report_errors(); }