Warning: This file is not a C or C++ file. It does not have highlighting.

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

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of libcxx/include/__cxx03/__memory/auto_ptr.h