以下代码出自于VS2012
复制代码
1 template
2 class shared_ptr
3 : public _Ptr_base<_Ty>
4 { // class for reference counted resource management
5 public:
6 typedef shared_ptr<_Ty> _Myt;
7 typedef _Ptr_base<_Ty> _Mybase;
8
9 shared_ptr() _NOEXCEPT
10 { // construct empty shared_ptr object
11 }
12
13 template
14 explicit shared_ptr(_Ux *_Px)
15 { // construct shared_ptr object that owns _Px
16 _Resetp(_Px);
17 }
18
19 template
20 class _Dx>
21 shared_ptr(_Ux *_Px, _Dx _Dt)
22 { // construct with _Px, deleter
23 _Resetp(_Px, _Dt);
24 }
25
26 //#if _HAS_CPP0X
27
28 shared_ptr(nullptr_t)
29 { // construct with nullptr
30 _Resetp((_Ty *)0);
31 }
32
33 template
34 shared_ptr(nullptr_t, _Dx _Dt)
35 { // construct with nullptr, deleter
36 _Resetp((_Ty *)0, _Dt);
37 }
38
39 template
40 class _Alloc>
41 shared_ptr(nullptr_t, _Dx _Dt, _Alloc _Ax)
42 { // construct with nullptr, deleter, allocator
43 _Resetp((_Ty *)0, _Dt, _Ax);
44 }
45
46 template
47 class _Dx,
48 class _Alloc>
49 shared_ptr(_Ux *_Px, _Dx _Dt, _Alloc _Ax)
50 { // construct with _Px, deleter, allocator
51 _Resetp(_Px, _Dt, _Ax);
52 }
53 //#endif /* _HAS_CPP0X */
54
55 #if _HAS_CPP0X
56 template
57 shared_ptr(const shared_ptr<_Ty2>& _Right, _Ty *_Px) _NOEXCEPT
58 { // construct shared_ptr object that aliases _Right
59 this->_Reset(_Px, _Right);
60 }
61 #endif /* _HAS_CPP0X */
62
63 shared_ptr(const _Myt& _Other) _NOEXCEPT
64 { // construct shared_ptr object that owns same resource as _Other
65 this->_Reset(_Other);
66 }
67
68 template
69 shared_ptr(const shared_ptr<_Ty2>& _Other,
70 typename enable_if::value,
71 void>::type ** = 0) _NOEXCEPT
72 { // construct shared_ptr object that owns same resource as _Other
73 this->_Reset(_Other);
74 }
75
76 template
77 explicit shared_ptr(const weak_ptr<_Ty2>& _Other,
78 bool _Throw = true)
79 { // construct shared_ptr object that owns resource *_Other
80 this->_Reset(_Other, _Throw);
81 }
82
83 template
84 shared_ptr(auto_ptr<_Ty2>&& _Other)
85 { // construct shared_ptr object that owns *_Other.get()
86 this->_Reset(_STD move(_Other));
87 }
88
89 template
90 shared_ptr(const shared_ptr<_Ty2>& _Other, const _Static_tag& _Tag)
91 { // construct shared_ptr object for static_pointer_cast
92 this->_Reset(_Other, _Tag);
93 }
94
95 template
96 shared_ptr(const shared_ptr<_Ty2>& _Other, const _Const_tag& _Tag)
97 { // construct shared_ptr object for const_pointer_cast
98 this->_Reset(_Other, _Tag);
99 }
100
101 template
102 shared_ptr(const shared_ptr<_Ty2>& _Other, const _Dynamic_tag& _Tag)
103 { // construct shared_ptr object for dynamic_pointer_cast
104 this->_Reset(_Other, _Tag);
105 }
106