Home | History | Annotate | Line # | Download | only in __memory
      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 
     15 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
     16 #pragma GCC system_header
     17 #endif
     18 
     19 _LIBCPP_PUSH_MACROS
     20 #include <__undef_macros>
     21 
     22 _LIBCPP_BEGIN_NAMESPACE_STD
     23 
     24 template <class _Tp>
     25 struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref
     26 {
     27     _Tp* __ptr_;
     28 };
     29 
     30 template<class _Tp>
     31 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr
     32 {
     33 private:
     34     _Tp* __ptr_;
     35 public:
     36     typedef _Tp element_type;
     37 
     38     _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) _NOEXCEPT : __ptr_(__p) {}
     39     _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) _NOEXCEPT : __ptr_(__p.release()) {}
     40     template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) _NOEXCEPT
     41         : __ptr_(__p.release()) {}
     42     _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) _NOEXCEPT
     43         {reset(__p.release()); return *this;}
     44     template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) _NOEXCEPT
     45         {reset(__p.release()); return *this;}
     46     _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) _NOEXCEPT
     47         {reset(__p.__ptr_); return *this;}
     48     _LIBCPP_INLINE_VISIBILITY ~auto_ptr() _NOEXCEPT {delete __ptr_;}
     49 
     50     _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const _NOEXCEPT
     51         {return *__ptr_;}
     52     _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const _NOEXCEPT {return __ptr_;}
     53     _LIBCPP_INLINE_VISIBILITY _Tp* get() const _NOEXCEPT {return __ptr_;}
     54     _LIBCPP_INLINE_VISIBILITY _Tp* release() _NOEXCEPT
     55     {
     56         _Tp* __t = __ptr_;
     57         __ptr_ = nullptr;
     58         return __t;
     59     }
     60     _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) _NOEXCEPT
     61     {
     62         if (__ptr_ != __p)
     63             delete __ptr_;
     64         __ptr_ = __p;
     65     }
     66 
     67     _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) _NOEXCEPT : __ptr_(__p.__ptr_) {}
     68     template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() _NOEXCEPT
     69         {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
     70     template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() _NOEXCEPT
     71         {return auto_ptr<_Up>(release());}
     72 };
     73 
     74 template <>
     75 class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void>
     76 {
     77 public:
     78     typedef void element_type;
     79 };
     80 
     81 _LIBCPP_END_NAMESPACE_STD
     82 
     83 _LIBCPP_POP_MACROS
     84 
     85 #endif // _LIBCPP___MEMORY_AUTO_PTR_H
     86