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"); }
121 : _M_t(__p, deleter_type())
123 "constructed with null function pointer deleter"); }
127 deleter_type,
const deleter_type&>::type __d) noexcept
131 typename std::remove_reference<deleter_type>::type&& __d) noexcept
132 : _M_t(std::move(__p), std::move(__d))
134 "rvalue deleter bound to reference"); }
139 "constructed with null function pointer deleter"); }
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()) { }
171 auto& __ptr = std::get<0>(_M_t);
172 if (__ptr !=
nullptr)
173 get_deleter()(__ptr);
181 reset(__u.release());
182 get_deleter() = std::forward<deleter_type>(__u.get_deleter());
186 template<
typename _Up,
typename _Ep,
typename =
typename
194 reset(__u.release());
195 get_deleter() = std::forward<_Ep>(__u.get_deleter());
200 operator=(nullptr_t) noexcept
207 typename std::add_lvalue_reference<element_type>::type
210 _GLIBCXX_DEBUG_ASSERT(
get() != pointer());
215 operator->()
const noexcept
217 _GLIBCXX_DEBUG_ASSERT(
get() != pointer());
223 {
return std::get<0>(_M_t); }
226 get_deleter() noexcept
227 {
return std::get<1>(_M_t); }
230 get_deleter()
const noexcept
231 {
return std::get<1>(_M_t); }
233 explicit operator bool()
const noexcept
234 {
return get() == pointer() ?
false :
true; }
241 std::get<0>(_M_t) = pointer();
246 reset(pointer __p = pointer()) noexcept
249 swap(std::get<0>(_M_t), __p);
250 if (__p != pointer())
258 swap(_M_t, __u._M_t);
270 template<
typename _Tp,
typename _Dp>
277 typedef _Tp* pointer;
278 typedef _Tp element_type;
279 typedef _Dp deleter_type;
285 "constructed with null function pointer deleter"); }
289 : _M_t(__p, deleter_type())
291 "constructed with null function pointer deleter"); }
295 deleter_type,
const deleter_type&>::type __d) noexcept
299 std::remove_reference<deleter_type>::type && __d) noexcept
300 : _M_t(std::move(__p), std::move(__d))
302 "rvalue deleter bound to reference"); }
307 "constructed with null function pointer deleter"); }
311 : _M_t(__u.release(), std::forward<deleter_type>(__u.get_deleter())) { }
313 template<
typename _Up,
typename _Ep>
315 : _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter()))
321 auto& __ptr = std::get<0>(_M_t);
322 if (__ptr !=
nullptr)
323 get_deleter()(__ptr);
331 reset(__u.release());
332 get_deleter() = std::forward<deleter_type>(__u.get_deleter());
336 template<
typename _Up,
typename _Ep>
340 reset(__u.release());
341 get_deleter() = std::forward<_Ep>(__u.get_deleter());
346 operator=(nullptr_t) noexcept
353 typename std::add_lvalue_reference<element_type>::type
356 _GLIBCXX_DEBUG_ASSERT(
get() != pointer());
362 {
return std::get<0>(_M_t); }
365 get_deleter() noexcept
366 {
return std::get<1>(_M_t); }
369 get_deleter()
const noexcept
370 {
return std::get<1>(_M_t); }
372 explicit operator bool()
const noexcept
373 {
return get() == pointer() ?
false :
true; }
380 std::get<0>(_M_t) = pointer();
385 reset(pointer __p = pointer()) noexcept
388 swap(std::get<0>(_M_t), __p);
394 reset(nullptr_t) noexcept
397 std::get<0>(_M_t) = pointer();
403 template<
typename _Up>
404 void reset(_Up) =
delete;
410 swap(_M_t, __u._M_t);
419 template<
typename _Up>
422 deleter_type,
const deleter_type&>::type,
424 pointer>::value>::type* = 0) =
delete;
426 template<
typename _Up>
427 unique_ptr(_Up*,
typename std::remove_reference<deleter_type>::type&&,
429 pointer>::value>::type* = 0) =
delete;
431 template<
typename _Up>
434 pointer>::value>::type* = 0) =
delete;
437 template<
typename _Tp,
typename _Dp>
443 template<
typename _Tp,
typename _Dp,
444 typename _Up,
typename _Ep>
446 operator==(
const unique_ptr<_Tp, _Dp>& __x,
447 const unique_ptr<_Up, _Ep>& __y)
448 {
return __x.get() == __y.get(); }
450 template<
typename _Tp,
typename _Dp>
452 operator==(
const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept
455 template<
typename _Tp,
typename _Dp>
457 operator==(nullptr_t,
const unique_ptr<_Tp, _Dp>& __x) noexcept
460 template<
typename _Tp,
typename _Dp,
461 typename _Up,
typename _Ep>
463 operator!=(
const unique_ptr<_Tp, _Dp>& __x,
464 const unique_ptr<_Up, _Ep>& __y)
465 {
return __x.get() != __y.get(); }
467 template<
typename _Tp,
typename _Dp>
469 operator!=(
const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept
470 {
return (
bool)__x; }
472 template<
typename _Tp,
typename _Dp>
474 operator!=(nullptr_t,
const unique_ptr<_Tp, _Dp>& __x) noexcept
475 {
return (
bool)__x; }
477 template<
typename _Tp,
typename _Dp,
478 typename _Up,
typename _Ep>
480 operator<(const unique_ptr<_Tp, _Dp>& __x,
481 const unique_ptr<_Up, _Ep>& __y)
485 typename unique_ptr<_Up, _Ep>::pointer>::type _CT;
489 template<
typename _Tp,
typename _Dp>
491 operator<(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
495 template<
typename _Tp,
typename _Dp>
497 operator<(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
501 template<
typename _Tp,
typename _Dp,
502 typename _Up,
typename _Ep>
504 operator<=(const unique_ptr<_Tp, _Dp>& __x,
505 const unique_ptr<_Up, _Ep>& __y)
506 {
return !(__y < __x); }
508 template<
typename _Tp,
typename _Dp>
510 operator<=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
511 {
return !(
nullptr < __x); }
513 template<
typename _Tp,
typename _Dp>
515 operator<=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
516 {
return !(__x <
nullptr); }
518 template<
typename _Tp,
typename _Dp,
519 typename _Up,
typename _Ep>
521 operator>(
const unique_ptr<_Tp, _Dp>& __x,
522 const unique_ptr<_Up, _Ep>& __y)
523 {
return (__y < __x); }
525 template<
typename _Tp,
typename _Dp>
527 operator>(
const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
531 template<
typename _Tp,
typename _Dp>
533 operator>(nullptr_t,
const unique_ptr<_Tp, _Dp>& __x)
537 template<
typename _Tp,
typename _Dp,
538 typename _Up,
typename _Ep>
540 operator>=(
const unique_ptr<_Tp, _Dp>& __x,
541 const unique_ptr<_Up, _Ep>& __y)
542 {
return !(__x < __y); }
544 template<
typename _Tp,
typename _Dp>
546 operator>=(
const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
547 {
return !(__x <
nullptr); }
549 template<
typename _Tp,
typename _Dp>
551 operator>=(nullptr_t,
const unique_ptr<_Tp, _Dp>& __x)
552 {
return !(
nullptr < __x); }
555 template<
typename _Tp,
typename _Dp>
557 :
public __hash_base<size_t, unique_ptr<_Tp, _Dp>>
569 _GLIBCXX_END_NAMESPACE_VERSION
20.7.12.2 unique_ptr for single objects.
Define a member typedef type only if a boolean constant is true.
A simple smart pointer providing strict ownership semantics.
One of the comparison functors.
reference operator[](size_t __position)
Array-indexing support.
Define a member typedef type to one of two argument types.
Primary template, default_delete.
Primary class template hash.