boost_no_auto_ptr.ipp 945 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // (C) Copyright John Maddock 2001.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/config for most recent version.
  6. // MACRO: BOOST_NO_AUTO_PTR
  7. // TITLE: std::auto_ptr
  8. // DESCRIPTION: If the compiler / library supplies non-standard or broken
  9. // std::auto_ptr.
  10. #include <memory>
  11. namespace boost_no_auto_ptr{
  12. template <class T>
  13. class my_ptr
  14. {
  15. T* p;
  16. public:
  17. my_ptr(std::auto_ptr<T>& r)
  18. {
  19. p = r.release();
  20. }
  21. my_ptr& operator=(std::auto_ptr<T>& r)
  22. {
  23. delete p;
  24. p = r.release();
  25. return *this;
  26. }
  27. ~my_ptr()
  28. {
  29. delete p;
  30. }
  31. };
  32. int test()
  33. {
  34. std::auto_ptr<int> ap1(new int);
  35. my_ptr<int> mp(ap1);
  36. std::auto_ptr<int> ap2(new int);
  37. mp = ap2;
  38. return 0;
  39. }
  40. }