1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5 // See https://llvm.org/LICENSE.txt for license information. 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP___MEMORY_AUTO_PTR_H 11 #define _LIBCPP___MEMORY_AUTO_PTR_H 12 13 #include <__config> 14 #include <__nullptr> 15 16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 17 #pragma GCC system_header 18 #endif 19 20 _LIBCPP_BEGIN_NAMESPACE_STD 21 22 template <class _Tp> 23 struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref 24 { 25 _Tp* __ptr_; 26 }; 27 28 template<class _Tp> 29 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr 30 { 31 private: 32 _Tp* __ptr_; 33 public: 34 typedef _Tp element_type; 35 36 _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) _NOEXCEPT : __ptr_(__p) {} 37 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) _NOEXCEPT : __ptr_(__p.release()) {} 38 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) _NOEXCEPT 39 : __ptr_(__p.release()) {} 40 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) _NOEXCEPT 41 {reset(__p.release()); return *this;} 42 template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) _NOEXCEPT 43 {reset(__p.release()); return *this;} 44 _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) _NOEXCEPT 45 {reset(__p.__ptr_); return *this;} 46 _LIBCPP_INLINE_VISIBILITY ~auto_ptr() _NOEXCEPT {delete __ptr_;} 47 48 _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const _NOEXCEPT 49 {return *__ptr_;} 50 _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const _NOEXCEPT {return __ptr_;} 51 _LIBCPP_INLINE_VISIBILITY _Tp* get() const _NOEXCEPT {return __ptr_;} 52 _LIBCPP_INLINE_VISIBILITY _Tp* release() _NOEXCEPT 53 { 54 _Tp* __t = __ptr_; 55 __ptr_ = nullptr; 56 return __t; 57 } 58 _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) _NOEXCEPT 59 { 60 if (__ptr_ != __p) 61 delete __ptr_; 62 __ptr_ = __p; 63 } 64 65 _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) _NOEXCEPT : __ptr_(__p.__ptr_) {} 66 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() _NOEXCEPT 67 {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;} 68 template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() _NOEXCEPT 69 {return auto_ptr<_Up>(release());} 70 }; 71 72 template <> 73 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void> 74 { 75 public: 76 typedef void element_type; 77 }; 78 79 _LIBCPP_END_NAMESPACE_STD 80 81 #endif // _LIBCPP___MEMORY_AUTO_PTR_H 82