sp_unary_addr_test.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // sp_unary_addr_test.cpp
  3. //
  4. // Copyright (c) 2007 Peter Dimov
  5. //
  6. // Distributed under the Boost Software License, Version 1.0. (See
  7. // accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #include <boost/shared_ptr.hpp>
  11. #include <boost/detail/lightweight_test.hpp>
  12. #include <memory>
  13. struct deleter
  14. {
  15. private:
  16. void operator& ();
  17. void operator& () const;
  18. public:
  19. int data;
  20. deleter(): data( 17041 )
  21. {
  22. }
  23. void operator()( void * )
  24. {
  25. }
  26. };
  27. struct X
  28. {
  29. };
  30. int main()
  31. {
  32. X x;
  33. {
  34. boost::shared_ptr<X> p( &x, deleter() );
  35. deleter * q = boost::get_deleter<deleter>( p );
  36. BOOST_TEST( q != 0 );
  37. BOOST_TEST( q != 0 && q->data == 17041 );
  38. }
  39. #if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, < 1300 )
  40. #else
  41. {
  42. boost::shared_ptr<X> p( &x, deleter(), std::allocator<X>() );
  43. deleter * q = boost::get_deleter<deleter>( p );
  44. BOOST_TEST( q != 0 );
  45. BOOST_TEST( q != 0 && q->data == 17041 );
  46. }
  47. #endif
  48. return boost::report_errors();
  49. }