31 #define _UNIQUE_PTR_H 1
39 namespace std _GLIBCXX_VISIBILITY(default)
41 _GLIBCXX_BEGIN_NAMESPACE_VERSION
49 template<
typename _Tp>
54 template<
typename _Up,
typename =
typename
59 operator()(_Tp* __ptr)
const
61 static_assert(
sizeof(_Tp)>0,
62 "can't delete pointer to incomplete type");
70 template<
typename _Tp>
76 operator()(_Tp* __ptr)
const
78 static_assert(
sizeof(_Tp)>0,
79 "can't delete pointer to incomplete type");
83 template<
typename _Up>
void operator()(_Up*)
const =
delete;
87 template <
typename _Tp,
typename _Dp = default_delete<_Tp> >
93 template<
typename _Up>
94 static typename _Up::pointer __test(
typename _Up::pointer*);
96 template<
typename _Up>
97 static _Tp* __test(...);
99 typedef typename remove_reference<_Dp>::type _Del;
102 typedef decltype( __test<_Del>(0)) type;
109 typedef typename _Pointer::type pointer;
110 typedef _Tp element_type;
111 typedef _Dp deleter_type;
117 "constructed with null function pointer deleter"); }
120 unique_ptr(pointer __p)
121 : _M_t(__p, deleter_type())
123 "constructed with null function pointer deleter"); }
125 unique_ptr(pointer __p,
127 deleter_type,
const deleter_type&>::type __d)
130 unique_ptr(pointer __p,
131 typename std::remove_reference<deleter_type>::type&& __d)
132 : _M_t(std::move(__p), std::move(__d))
134 "rvalue deleter bound to reference"); }
136 constexpr unique_ptr(nullptr_t)
139 "constructed with null function pointer deleter"); }
142 unique_ptr(unique_ptr&& __u)
143 : _M_t(__u.release(), std::forward<deleter_type>(__u.get_deleter())) { }
145 template<
typename _Up,
typename _Ep,
typename =
typename
156 : _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter()))
159 #if _GLIBCXX_USE_DEPRECATED
160 template<
typename _Up,
typename =
typename
165 : _M_t(__u.release(), deleter_type()) { }
169 ~unique_ptr() { reset(); }
173 operator=(unique_ptr&& __u)
175 reset(__u.release());
176 get_deleter() = std::forward<deleter_type>(__u.get_deleter());
180 template<
typename _Up,
typename _Ep,
typename =
typename
188 reset(__u.release());
189 get_deleter() = std::forward<_Ep>(__u.get_deleter());
201 typename std::add_lvalue_reference<element_type>::type
204 _GLIBCXX_DEBUG_ASSERT(
get() != pointer());
211 _GLIBCXX_DEBUG_ASSERT(
get() != pointer());
217 {
return std::get<0>(_M_t); }
221 {
return std::get<1>(_M_t); }
225 {
return std::get<1>(_M_t); }
227 explicit operator bool()
const
228 {
return get() == pointer() ?
false :
true; }
235 std::get<0>(_M_t) = pointer();
240 reset(pointer __p = pointer())
243 swap(std::get<0>(_M_t), __p);
244 if (__p != pointer())
249 swap(unique_ptr& __u)
252 swap(_M_t, __u._M_t);
256 unique_ptr(
const unique_ptr&) =
delete;
257 unique_ptr& operator=(
const unique_ptr&) =
delete;
264 template<
typename _Tp,
typename _Dp>
271 typedef _Tp* pointer;
272 typedef _Tp element_type;
273 typedef _Dp deleter_type;
279 "constructed with null function pointer deleter"); }
282 unique_ptr(pointer __p)
283 : _M_t(__p, deleter_type())
285 "constructed with null function pointer deleter"); }
287 unique_ptr(pointer __p,
289 deleter_type,
const deleter_type&>::type __d)
292 unique_ptr(pointer __p,
293 typename std::remove_reference<deleter_type>::type && __d)
294 : _M_t(std::move(__p), std::move(__d))
296 "rvalue deleter bound to reference"); }
298 constexpr unique_ptr(nullptr_t)
301 "constructed with null function pointer deleter"); }
304 unique_ptr(unique_ptr&& __u)
305 : _M_t(__u.release(), std::forward<deleter_type>(__u.get_deleter())) { }
307 template<
typename _Up,
typename _Ep>
309 : _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter()))
313 ~unique_ptr() { reset(); }
317 operator=(unique_ptr&& __u)
319 reset(__u.release());
320 get_deleter() = std::forward<deleter_type>(__u.get_deleter());
324 template<
typename _Up,
typename _Ep>
328 reset(__u.release());
329 get_deleter() = std::forward<_Ep>(__u.get_deleter());
341 typename std::add_lvalue_reference<element_type>::type
344 _GLIBCXX_DEBUG_ASSERT(
get() != pointer());
350 {
return std::get<0>(_M_t); }
354 {
return std::get<1>(_M_t); }
358 {
return std::get<1>(_M_t); }
360 explicit operator bool()
const
361 {
return get() == pointer() ?
false :
true; }
368 std::get<0>(_M_t) = pointer();
373 reset(pointer __p = pointer())
376 swap(std::get<0>(_M_t), __p);
385 std::get<0>(_M_t) = pointer();
391 template<
typename _Up>
392 void reset(_Up) =
delete;
395 swap(unique_ptr& __u)
398 swap(_M_t, __u._M_t);
402 unique_ptr(
const unique_ptr&) =
delete;
403 unique_ptr& operator=(
const unique_ptr&) =
delete;
407 template<
typename _Up>
408 unique_ptr(_Up*,
typename
410 deleter_type,
const deleter_type&>::type,
412 pointer>::value>::type* = 0) =
delete;
414 template<
typename _Up>
415 unique_ptr(_Up*,
typename std::remove_reference<deleter_type>::type&&,
417 pointer>::value>::type* = 0) =
delete;
419 template<
typename _Up>
422 pointer>::value>::type* = 0) =
delete;
425 template<
typename _Tp,
typename _Dp>
431 template<
typename _Tp,
typename _Dp,
432 typename _Up,
typename _Ep>
434 operator==(
const unique_ptr<_Tp, _Dp>& __x,
435 const unique_ptr<_Up, _Ep>& __y)
436 {
return __x.get() == __y.get(); }
438 template<
typename _Tp,
typename _Dp>
440 operator==(
const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
441 {
return __x.get() ==
nullptr; }
443 template<
typename _Tp,
typename _Dp>
445 operator==(nullptr_t,
const unique_ptr<_Tp, _Dp>& __y)
446 {
return nullptr == __y.get(); }
448 template<
typename _Tp,
typename _Dp,
449 typename _Up,
typename _Ep>
451 operator!=(
const unique_ptr<_Tp, _Dp>& __x,
452 const unique_ptr<_Up, _Ep>& __y)
453 {
return !(__x.get() == __y.get()); }
455 template<
typename _Tp,
typename _Dp>
457 operator!=(
const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
458 {
return __x.get() !=
nullptr; }
460 template<
typename _Tp,
typename _Dp>
462 operator!=(nullptr_t,
const unique_ptr<_Tp, _Dp>& __y)
463 {
return nullptr != __y.get(); }
465 template<
typename _Tp,
typename _Dp,
466 typename _Up,
typename _Ep>
468 operator<(const unique_ptr<_Tp, _Dp>& __x,
469 const unique_ptr<_Up, _Ep>& __y)
470 {
return __x.get() < __y.get(); }
472 template<
typename _Tp,
typename _Dp,
473 typename _Up,
typename _Ep>
475 operator<=(const unique_ptr<_Tp, _Dp>& __x,
476 const unique_ptr<_Up, _Ep>& __y)
477 {
return !(__y.get() < __x.get()); }
479 template<
typename _Tp,
typename _Dp,
480 typename _Up,
typename _Ep>
482 operator>(
const unique_ptr<_Tp, _Dp>& __x,
483 const unique_ptr<_Up, _Ep>& __y)
484 {
return __y.get() < __x.get(); }
486 template<
typename _Tp,
typename _Dp,
487 typename _Up,
typename _Ep>
489 operator>=(
const unique_ptr<_Tp, _Dp>& __x,
490 const unique_ptr<_Up, _Ep>& __y)
491 {
return !(__x.get() < __y.get()); }
494 template<
typename _Tp,
typename _Dp>
508 _GLIBCXX_END_NAMESPACE_VERSION
reference operator[](size_t __position)
Array-indexing support.
A simple smart pointer providing strict ownership semantics.
20.7.12.2 unique_ptr for single objects.
Primary class template hash.
Primary template, default_delete.