OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkUniquePtr_DEFINED | 8 #ifndef SkUniquePtr_DEFINED |
9 #define SkUniquePtr_DEFINED | 9 #define SkUniquePtr_DEFINED |
10 | 10 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 87 } |
88 void swap(compressed_data& that) /*noexcept*/ { | 88 void swap(compressed_data& that) /*noexcept*/ { |
89 compressed_base<deleter_type>::swap(static_cast<compressed_base<dele
ter_type>>(that)); | 89 compressed_base<deleter_type>::swap(static_cast<compressed_base<dele
ter_type>>(that)); |
90 SkTSwap(fPtr, that.fPtr); | 90 SkTSwap(fPtr, that.fPtr); |
91 } | 91 } |
92 }; | 92 }; |
93 compressed_data data; | 93 compressed_data data; |
94 | 94 |
95 public: | 95 public: |
96 /*constexpr*/ unique_ptr() /*noexcept*/ : data() { | 96 /*constexpr*/ unique_ptr() /*noexcept*/ : data() { |
97 static_assert(!is_pointer<deleter_type>::value, "Deleter is nullptr func
tion pointer!"); | 97 static_assert(!std::is_pointer<deleter_type>::value, "Deleter nullptr fu
nction pointer!"); |
98 } | 98 } |
99 | 99 |
100 /*constexpr*/ unique_ptr(std::nullptr_t) /*noexcept*/ : unique_ptr() { } | 100 /*constexpr*/ unique_ptr(std::nullptr_t) /*noexcept*/ : unique_ptr() { } |
101 | 101 |
102 explicit unique_ptr(pointer ptr) /*noexcept*/ : data(ptr, deleter_type()) { | 102 explicit unique_ptr(pointer ptr) /*noexcept*/ : data(ptr, deleter_type()) { |
103 static_assert(!is_pointer<deleter_type>::value, "Deleter is nullptr func
tion pointer!"); | 103 static_assert(!std::is_pointer<deleter_type>::value, "Deleter nullptr fu
nction pointer!"); |
104 } | 104 } |
105 | 105 |
106 unique_ptr(pointer ptr, | 106 unique_ptr(pointer ptr, |
107 conditional_t<is_reference<deleter_type>::value, deleter_type,con
st deleter_type&> d) | 107 conditional_t<std::is_reference<deleter_type>::value, |
| 108 deleter_type, const deleter_type&> d) |
108 /*noexcept*/ : data(ptr, d) | 109 /*noexcept*/ : data(ptr, d) |
109 {} | 110 {} |
110 | 111 |
111 unique_ptr(pointer ptr, remove_reference_t<deleter_type>&& d) /*noexcept*/ | 112 unique_ptr(pointer ptr, remove_reference_t<deleter_type>&& d) /*noexcept*/ |
112 : data(std::move(ptr), std::move(d)) | 113 : data(std::move(ptr), std::move(d)) |
113 { | 114 { |
114 static_assert(!is_reference<deleter_type>::value, | 115 static_assert(!std::is_reference<deleter_type>::value, |
115 "Binding an rvalue reference deleter as an lvalue reference deleter
is not allowed."); | 116 "Binding an rvalue reference deleter as an lvalue reference deleter
is not allowed."); |
116 } | 117 } |
117 | 118 |
118 | 119 |
119 unique_ptr(unique_ptr&& that) /*noexcept*/ | 120 unique_ptr(unique_ptr&& that) /*noexcept*/ |
120 : data(that.release(), std::forward<deleter_type>(that.get_deleter())) | 121 : data(that.release(), std::forward<deleter_type>(that.get_deleter())) |
121 {} | 122 {} |
122 | 123 |
123 template <typename U, typename ThatD, typename = enable_if_t< | 124 template <typename U, typename ThatD, typename = enable_if_t< |
124 is_convertible<typename unique_ptr<U, ThatD>::pointer, pointer>::value &
& | 125 is_convertible<typename unique_ptr<U, ThatD>::pointer, pointer>::value &
& |
125 !is_array<U>::value && | 126 !std::is_array<U>::value && |
126 conditional_t<is_reference<D>::value, is_same<ThatD, D>, is_convertible<
ThatD, D>>::value>> | 127 conditional_t<std::is_reference<D>::value, |
| 128 std::is_same<ThatD, D>, |
| 129 is_convertible<ThatD, D>>::value>> |
127 unique_ptr(unique_ptr<U, ThatD>&& that) /*noexcept*/ | 130 unique_ptr(unique_ptr<U, ThatD>&& that) /*noexcept*/ |
128 : data(that.release(), std::forward<ThatD>(that.get_deleter())) | 131 : data(that.release(), std::forward<ThatD>(that.get_deleter())) |
129 {} | 132 {} |
130 | 133 |
131 ~unique_ptr() /*noexcept*/ { | 134 ~unique_ptr() /*noexcept*/ { |
132 pointer& ptr = data.getPointer(); | 135 pointer& ptr = data.getPointer(); |
133 if (ptr != nullptr) { | 136 if (ptr != nullptr) { |
134 get_deleter()(ptr); | 137 get_deleter()(ptr); |
135 } | 138 } |
136 ptr = pointer(); | 139 ptr = pointer(); |
137 } | 140 } |
138 | 141 |
139 unique_ptr& operator=(unique_ptr&& that) /*noexcept*/ { | 142 unique_ptr& operator=(unique_ptr&& that) /*noexcept*/ { |
140 reset(that.release()); | 143 reset(that.release()); |
141 get_deleter() = std::forward<deleter_type>(that.get_deleter()); | 144 get_deleter() = std::forward<deleter_type>(that.get_deleter()); |
142 return *this; | 145 return *this; |
143 } | 146 } |
144 | 147 |
145 template <typename U, typename ThatD> enable_if_t< | 148 template <typename U, typename ThatD> enable_if_t< |
146 is_convertible<typename unique_ptr<U, ThatD>::pointer, pointer>::value &
& | 149 is_convertible<typename unique_ptr<U, ThatD>::pointer, pointer>::value &
& |
147 !is_array<U>::value, | 150 !std::is_array<U>::value, |
148 unique_ptr&> operator=(unique_ptr<U, ThatD>&& that) /*noexcept*/ { | 151 unique_ptr&> operator=(unique_ptr<U, ThatD>&& that) /*noexcept*/ { |
149 reset(that.release()); | 152 reset(that.release()); |
150 get_deleter() = std::forward<ThatD>(that.get_deleter()); | 153 get_deleter() = std::forward<ThatD>(that.get_deleter()); |
151 return *this; | 154 return *this; |
152 } | 155 } |
153 | 156 |
154 unique_ptr& operator=(std::nullptr_t) /*noexcept*/ { | 157 unique_ptr& operator=(std::nullptr_t) /*noexcept*/ { |
155 reset(); | 158 reset(); |
156 return *this; | 159 return *this; |
157 } | 160 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 260 } |
258 void swap(compressed_data& that) /*noexcept*/ { | 261 void swap(compressed_data& that) /*noexcept*/ { |
259 compressed_base<deleter_type>::swap(static_cast<compressed_base<dele
ter_type>>(that)); | 262 compressed_base<deleter_type>::swap(static_cast<compressed_base<dele
ter_type>>(that)); |
260 SkTSwap(fPtr, that.fPtr); | 263 SkTSwap(fPtr, that.fPtr); |
261 } | 264 } |
262 }; | 265 }; |
263 compressed_data data; | 266 compressed_data data; |
264 | 267 |
265 public: | 268 public: |
266 /*constexpr*/ unique_ptr() /*noexcept*/ : data() { | 269 /*constexpr*/ unique_ptr() /*noexcept*/ : data() { |
267 static_assert(!is_pointer<deleter_type>::value, "Deleter is nullptr func
tion pointer!"); | 270 static_assert(!std::is_pointer<deleter_type>::value, "Deleter nullptr fu
nction pointer!"); |
268 } | 271 } |
269 | 272 |
270 /*constexpr*/ unique_ptr(std::nullptr_t) /*noexcept*/ : unique_ptr() { } | 273 /*constexpr*/ unique_ptr(std::nullptr_t) /*noexcept*/ : unique_ptr() { } |
271 | 274 |
272 explicit unique_ptr(pointer ptr) /*noexcept*/ : data(ptr, deleter_type()) { | 275 explicit unique_ptr(pointer ptr) /*noexcept*/ : data(ptr, deleter_type()) { |
273 static_assert(!is_pointer<deleter_type>::value, "Deleter is nullptr func
tion pointer!"); | 276 static_assert(!std::is_pointer<deleter_type>::value, "Deleter nullptr fu
nction pointer!"); |
274 } | 277 } |
275 | 278 |
276 unique_ptr(pointer ptr, | 279 unique_ptr(pointer ptr, |
277 conditional_t<is_reference<deleter_type>::value, deleter_type,con
st deleter_type&> d) | 280 conditional_t<std::is_reference<deleter_type>::value, |
| 281 deleter_type, const deleter_type&> d) |
278 /*noexcept*/ : data(ptr, d) | 282 /*noexcept*/ : data(ptr, d) |
279 {} | 283 {} |
280 | 284 |
281 unique_ptr(pointer ptr, remove_reference_t<deleter_type>&& d) /*noexcept*/ | 285 unique_ptr(pointer ptr, remove_reference_t<deleter_type>&& d) /*noexcept*/ |
282 : data(std::move(ptr), std::move(d)) | 286 : data(std::move(ptr), std::move(d)) |
283 { | 287 { |
284 static_assert(!is_reference<deleter_type>::value, | 288 static_assert(!std::is_reference<deleter_type>::value, |
285 "Binding an rvalue reference deleter as an lvalue reference deleter
is not allowed."); | 289 "Binding an rvalue reference deleter as an lvalue reference deleter
is not allowed."); |
286 } | 290 } |
287 | 291 |
288 unique_ptr(unique_ptr&& that) /*noexcept*/ | 292 unique_ptr(unique_ptr&& that) /*noexcept*/ |
289 : data(that.release(), std::forward<deleter_type>(that.get_deleter())) | 293 : data(that.release(), std::forward<deleter_type>(that.get_deleter())) |
290 {} | 294 {} |
291 | 295 |
292 ~unique_ptr() { | 296 ~unique_ptr() { |
293 pointer& ptr = data.getPointer(); | 297 pointer& ptr = data.getPointer(); |
294 if (ptr != nullptr) { | 298 if (ptr != nullptr) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 392 |
389 template <typename T, typename D> | 393 template <typename T, typename D> |
390 inline bool operator!=(std::nullptr_t, const unique_ptr<T, D>& b) /*noexcept*/ { | 394 inline bool operator!=(std::nullptr_t, const unique_ptr<T, D>& b) /*noexcept*/ { |
391 //return (bool)b; | 395 //return (bool)b; |
392 return b.is_attached(); | 396 return b.is_attached(); |
393 } | 397 } |
394 | 398 |
395 } // namespace skstd | 399 } // namespace skstd |
396 | 400 |
397 #endif | 401 #endif |
OLD | NEW |