1
1
#ifndef _GHLIBCPP_MEMORY
2
2
#define _GHLIBCPP_MEMORY
3
- #include " stddef.h"
4
3
#include " exception.h"
4
+ #include " stddef.h"
5
5
6
6
namespace std {
7
7
@@ -18,6 +18,7 @@ template <typename T> struct default_delete<T[]> {
18
18
template <typename T, typename Deleter = std::default_delete<T>>
19
19
class unique_ptr {
20
20
public:
21
+ typedef T *pointer;
21
22
unique_ptr () {}
22
23
unique_ptr (T *ptr) {}
23
24
unique_ptr (const unique_ptr<T> &t) = delete ;
@@ -27,9 +28,7 @@ class unique_ptr {
27
28
T *operator ->() const noexcept { return ptr; }
28
29
T *get () const noexcept { return ptr; }
29
30
T *release () { return ptr; }
30
- void reset () {}
31
- void reset (T *ptr) {}
32
- void reset (T ptr) {}
31
+ void reset (pointer __p = pointer()) {}
33
32
T *get () { return ptr; }
34
33
unique_ptr<T> &operator =(const unique_ptr &) = delete ;
35
34
unique_ptr<T> &operator =(unique_ptr &&) { return *this ; }
@@ -70,23 +69,29 @@ template <class T, class D> class unique_ptr<T[], D> {
70
69
template <class T , class ... Args> unique_ptr<T> make_unique (Args &&...args);
71
70
template <class T > unique_ptr<T> make_unique (size_t n);
72
71
73
- template <typename T> class shared_ptr {
72
+ template <typename T> class __shared_ptr {
73
+ public:
74
+ void reset () noexcept ;
75
+ template <class Y > void reset (Y *p);
76
+ template <class Y , class D > void reset (Y *p, D d);
77
+ template <class Y , class D , class A > void reset (Y *p, D d, A a);
78
+ };
79
+
80
+ template <typename T> class shared_ptr : public __shared_ptr <T> {
74
81
public:
75
- shared_ptr () {}
76
- shared_ptr (T *ptr) {}
82
+ shared_ptr ();
83
+ shared_ptr (T *ptr);
77
84
shared_ptr (const shared_ptr<T> &r) noexcept ;
78
85
template <class Y > shared_ptr (const shared_ptr<Y> &r) noexcept ;
79
86
shared_ptr (shared_ptr<T> &&r) noexcept ;
80
87
template <class Y > shared_ptr (shared_ptr<Y> &&r) noexcept ;
81
88
shared_ptr (unique_ptr<T> &&t) {}
82
89
~shared_ptr () {}
83
- T &operator *() const { return *ptr; }
84
- T *operator ->() const noexcept { return ptr; }
85
- void reset () {}
86
- void reset (T *pt) {}
87
- void reset (T pt) {}
90
+ T &operator *() const noexcept ;
91
+ T *operator ->() const noexcept ;
92
+
88
93
long use_count () const noexcept { return 0 ; }
89
- T *get () { return ptr; }
94
+ T *get () const noexcept { return ptr; }
90
95
shared_ptr<T> &operator =(const shared_ptr &) {}
91
96
shared_ptr<T> &operator =(shared_ptr &&) { return *this ; }
92
97
template <typename S> shared_ptr &operator =(shared_ptr<T> &&) {
0 commit comments