Quantum-Chess 0.5
Chargement...
Recherche...
Aucune correspondance
observer_ptr.hpp
Aller à la documentation de ce fichier.
1#ifndef OBSERVER_PTR_HPP
2#define OBSERVER_PTR_HPP
3#include <memory>
4
5template <typename T>
7{
8public:
9 // publish our template parameter and variations thereof
10 using element_type = T;
11 using __pointer = std::add_pointer_t<T>; // exposition-only
12 using __reference = std::add_lvalue_reference_t<T>; // exposition-only
13
14 // 3.2.2, observer_ptr constructors
15 // default c'tor
16 constexpr observer_ptr() noexcept
17 : __t()
18 {
19 }
20
21 // pointer-accepting c'tors
22 constexpr observer_ptr(std::nullptr_t) noexcept
23 : __t()
24 {
25 }
26
27 constexpr explicit observer_ptr(__pointer __p) noexcept
28 : __t(__p)
29 {
30 }
31
32 // copying c'tors (in addition to compiler-generated copy c'tor)
33 template <typename _Up,
34 typename = typename std::enable_if<
35 std::is_convertible<
36 typename std::add_pointer<_Up>::type, __pointer>::
37 value>::type>
38
39 constexpr observer_ptr(observer_ptr<_Up> __p) noexcept
40 : __t(__p.get())
41 {
42 }
43
44 // 3.2.3, observer_ptr observers
45 constexpr __pointer
46 get() const noexcept
47 {
48 return __t;
49 }
50
51 constexpr __reference
52 operator*() const
53 {
54 return *get();
55 }
56
57 constexpr __pointer
58 operator->() const noexcept
59 {
60 return get();
61 }
62
63 constexpr explicit operator bool() const noexcept
64 {
65 return get() != nullptr;
66 }
67
68 // 3.2.4, observer_ptr conversions
69 constexpr explicit operator __pointer() const noexcept
70 {
71 return get();
72 }
73
74 // 3.2.5, observer_ptr modifiers
75 constexpr __pointer
76 release() noexcept
77 {
78 __pointer __tmp = get();
79 reset();
80 return __tmp;
81 }
82
83 constexpr void
84 reset(__pointer __p = nullptr) noexcept
85 {
86 __t = __p;
87 }
88
89 constexpr void
90 swap(observer_ptr &__p) noexcept
91 {
92 std::swap(__t, __p.__t);
93 }
94
95private:
97}; // observer_ptr<>
98
99template <typename T>
100void swap(observer_ptr<T> &__p1, observer_ptr<T> &__p2) noexcept
101{
102 __p1.swap(__p2);
103}
104
105template <typename T>
107make_observer(T *__p) noexcept
108{
109 return observer_ptr<T>(__p);
110}
111
112template <typename T, typename _Up>
114{
115 return __p1.get() == __p2.get();
116}
117
118template <typename T, typename _Up>
120{
121 return !(__p1 == __p2);
122}
123
124template <typename T>
125bool operator==(observer_ptr<T> __p, std::nullptr_t) noexcept
126{
127 return !__p;
128}
129
130template <typename T>
131bool operator==(std::nullptr_t, observer_ptr<T> __p) noexcept
132{
133 return !__p;
134}
135
136template <typename T>
137bool operator!=(observer_ptr<T> __p, std::nullptr_t) noexcept
138{
139 return bool(__p);
140}
141
142template <typename T>
143bool operator!=(std::nullptr_t, observer_ptr<T> __p) noexcept
144{
145 return bool(__p);
146}
147
148template <typename T, typename _Up>
150{
151 return std::less<
152 typename std::common_type<
153 typename std::add_pointer<T>::type,
154 typename std::add_pointer<_Up>::type>::type>{}(__p1.get(),
155 __p2.get());
156}
157
158template <typename T, typename _Up>
160{
161 return __p2 < __p1;
162}
163
164template <typename T, typename _Up>
166{
167 return !(__p2 < __p1);
168}
169
170template <typename T, typename _Up>
172{
173 return !(__p1 < __p2);
174}
175
176#endif
Definition observer_ptr.hpp:7
std::add_pointer_t< T > __pointer
Definition observer_ptr.hpp:11
constexpr observer_ptr() noexcept
Definition observer_ptr.hpp:16
constexpr __pointer operator->() const noexcept
Definition observer_ptr.hpp:58
T element_type
Definition observer_ptr.hpp:10
std::add_lvalue_reference_t< T > __reference
Definition observer_ptr.hpp:12
constexpr __pointer release() noexcept
Definition observer_ptr.hpp:76
constexpr void swap(observer_ptr &__p) noexcept
Definition observer_ptr.hpp:90
constexpr __reference operator*() const
Definition observer_ptr.hpp:52
constexpr observer_ptr(observer_ptr< _Up > __p) noexcept
Definition observer_ptr.hpp:39
constexpr observer_ptr(__pointer __p) noexcept
Definition observer_ptr.hpp:27
constexpr void reset(__pointer __p=nullptr) noexcept
Definition observer_ptr.hpp:84
constexpr __pointer get() const noexcept
Definition observer_ptr.hpp:46
constexpr observer_ptr(std::nullptr_t) noexcept
Definition observer_ptr.hpp:22
__pointer __t
Definition observer_ptr.hpp:96
void swap(observer_ptr< T > &__p1, observer_ptr< T > &__p2) noexcept
Definition observer_ptr.hpp:100
observer_ptr< T > make_observer(T *__p) noexcept
Definition observer_ptr.hpp:107
bool operator!=(observer_ptr< T > __p1, observer_ptr< _Up > __p2)
Definition observer_ptr.hpp:119
bool operator>(observer_ptr< T > __p1, observer_ptr< _Up > __p2)
Definition observer_ptr.hpp:159
bool operator<(observer_ptr< T > __p1, observer_ptr< _Up > __p2)
Definition observer_ptr.hpp:149
bool operator==(observer_ptr< T > __p1, observer_ptr< _Up > __p2)
Definition observer_ptr.hpp:113
bool operator>=(observer_ptr< T > __p1, observer_ptr< _Up > __p2)
Definition observer_ptr.hpp:171
bool operator<=(observer_ptr< T > __p1, observer_ptr< _Up > __p2)
Definition observer_ptr.hpp:165