1 2 #ifndef BOOST_CONTRACT_DETAIL_AUTO_PTR_HPP_ 3 #define BOOST_CONTRACT_DETAIL_AUTO_PTR_HPP_ 4 5 // Copyright (C) 2008-2018 Lorenzo Caminiti 6 // Distributed under the Boost Software License, Version 1.0 (see accompanying 7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). 8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html 9 10 #include <boost/contract/detail/operator_safe_bool.hpp> 11 #include <boost/contract/detail/debug.hpp> 12 #include <boost/config.hpp> 13 14 namespace boost { namespace contract { namespace detail { 15 16 // Using this instead of std::auto_ptr because std::auto_ptr will be removed in 17 // C++17 (this library always uses release() to avoid ownership issues). 18 template<typename T> 19 class auto_ptr { // Copyable (using default copy operations). 20 public: auto_ptr(T * ptr=0)21 explicit auto_ptr(T* ptr = 0) : ptr_(ptr) {} 22 BOOST_NOEXCEPT_IF(false)23 ~auto_ptr() BOOST_NOEXCEPT_IF(false) { delete ptr_; } 24 release()25 T* release() { 26 T* ptr = ptr_; 27 ptr_ = 0; 28 return ptr; 29 } 30 operator *()31 T& operator*() { 32 BOOST_CONTRACT_DETAIL_DEBUG(ptr_); 33 return *ptr_; 34 } 35 operator *() const36 T const& operator*() const { 37 BOOST_CONTRACT_DETAIL_DEBUG(ptr_); 38 return *ptr_; 39 } 40 operator ->()41 T* operator->() { return ptr_; } operator ->() const42 T const* operator->() const { return ptr_; } 43 44 BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(auto_ptr<T>, !!ptr_) 45 46 private: 47 T* ptr_; 48 }; 49 50 } } } // namespace 51 52 #endif // #include guard 53 54