/* Copyright 2017 Glen Joseph Fernandes (glenjofe@gmail.com) Distributed under the Boost Software License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) */ #include #include template class pointer { public: typedef typename boost::pointer_traits::element_type element_type; pointer(T value) : value_(value) { } T operator->() const BOOST_NOEXCEPT { return value_; } 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; { typedef int* 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 void* 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 const int* 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 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(); }