Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:26

0001 
0002 #ifndef BOOST_CONTRACT_DETAIL_AUTO_PTR_HPP_
0003 #define BOOST_CONTRACT_DETAIL_AUTO_PTR_HPP_
0004 
0005 // Copyright (C) 2008-2018 Lorenzo Caminiti
0006 // Distributed under the Boost Software License, Version 1.0 (see accompanying
0007 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
0008 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
0009 
0010 #include <boost/contract/detail/operator_safe_bool.hpp>
0011 #include <boost/contract/detail/debug.hpp>
0012 #include <boost/config.hpp>
0013 
0014 namespace boost { namespace contract { namespace detail {
0015 
0016 // Using this instead of std::auto_ptr because std::auto_ptr will be removed in
0017 // C++17 (this library always uses release() to avoid ownership issues).
0018 template<typename T>
0019 class auto_ptr { // Copyable (using default copy operations).
0020 public:
0021     explicit auto_ptr(T* ptr = 0) : ptr_(ptr) {}
0022 
0023     ~auto_ptr() BOOST_NOEXCEPT_IF(false) { delete ptr_; }
0024 
0025     T* release() {
0026         T* ptr = ptr_;
0027         ptr_ = 0;
0028         return ptr;
0029     }
0030 
0031     T& operator*() {
0032         BOOST_CONTRACT_DETAIL_DEBUG(ptr_);
0033         return *ptr_;
0034     }
0035     
0036     T const& operator*() const {
0037         BOOST_CONTRACT_DETAIL_DEBUG(ptr_);
0038         return *ptr_;
0039     }
0040 
0041     T* operator->() { return ptr_; }
0042     T const* operator->() const { return ptr_; }
0043 
0044     BOOST_CONTRACT_DETAIL_OPERATOR_SAFE_BOOL(auto_ptr<T>, !!ptr_)
0045 
0046 private:
0047     T* ptr_;
0048 };
0049 
0050 } } } // namespace
0051 
0052 #endif // #include guard
0053