Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/llvm-project/libcxx/include/__memory/auto_ptr.h
35233 views
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
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
20
21
_LIBCPP_BEGIN_NAMESPACE_STD
22
23
template <class _Tp>
24
struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref {
25
_Tp* __ptr_;
26
};
27
28
template <class _Tp>
29
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr {
30
private:
31
_Tp* __ptr_;
32
33
public:
34
typedef _Tp element_type;
35
36
_LIBCPP_HIDE_FROM_ABI explicit auto_ptr(_Tp* __p = 0) _NOEXCEPT : __ptr_(__p) {}
37
_LIBCPP_HIDE_FROM_ABI auto_ptr(auto_ptr& __p) _NOEXCEPT : __ptr_(__p.release()) {}
38
template <class _Up>
39
_LIBCPP_HIDE_FROM_ABI auto_ptr(auto_ptr<_Up>& __p) _NOEXCEPT : __ptr_(__p.release()) {}
40
_LIBCPP_HIDE_FROM_ABI auto_ptr& operator=(auto_ptr& __p) _NOEXCEPT {
41
reset(__p.release());
42
return *this;
43
}
44
template <class _Up>
45
_LIBCPP_HIDE_FROM_ABI auto_ptr& operator=(auto_ptr<_Up>& __p) _NOEXCEPT {
46
reset(__p.release());
47
return *this;
48
}
49
_LIBCPP_HIDE_FROM_ABI auto_ptr& operator=(auto_ptr_ref<_Tp> __p) _NOEXCEPT {
50
reset(__p.__ptr_);
51
return *this;
52
}
53
_LIBCPP_HIDE_FROM_ABI ~auto_ptr() _NOEXCEPT { delete __ptr_; }
54
55
_LIBCPP_HIDE_FROM_ABI _Tp& operator*() const _NOEXCEPT { return *__ptr_; }
56
_LIBCPP_HIDE_FROM_ABI _Tp* operator->() const _NOEXCEPT { return __ptr_; }
57
_LIBCPP_HIDE_FROM_ABI _Tp* get() const _NOEXCEPT { return __ptr_; }
58
_LIBCPP_HIDE_FROM_ABI _Tp* release() _NOEXCEPT {
59
_Tp* __t = __ptr_;
60
__ptr_ = nullptr;
61
return __t;
62
}
63
_LIBCPP_HIDE_FROM_ABI void reset(_Tp* __p = 0) _NOEXCEPT {
64
if (__ptr_ != __p)
65
delete __ptr_;
66
__ptr_ = __p;
67
}
68
69
_LIBCPP_HIDE_FROM_ABI auto_ptr(auto_ptr_ref<_Tp> __p) _NOEXCEPT : __ptr_(__p.__ptr_) {}
70
template <class _Up>
71
_LIBCPP_HIDE_FROM_ABI operator auto_ptr_ref<_Up>() _NOEXCEPT {
72
auto_ptr_ref<_Up> __t;
73
__t.__ptr_ = release();
74
return __t;
75
}
76
template <class _Up>
77
_LIBCPP_HIDE_FROM_ABI operator auto_ptr<_Up>() _NOEXCEPT {
78
return auto_ptr<_Up>(release());
79
}
80
};
81
82
template <>
83
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void> {
84
public:
85
typedef void element_type;
86
};
87
88
_LIBCPP_END_NAMESPACE_STD
89
90
#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
91
92
#endif // _LIBCPP___MEMORY_AUTO_PTR_H
93
94