31#define _UNIQUE_PTR_H 1
39namespace std _GLIBCXX_VISIBILITY(default)
41_GLIBCXX_BEGIN_NAMESPACE_VERSION
48#if _GLIBCXX_USE_DEPRECATED
49 template<
typename>
class auto_ptr;
53 template<
typename _Tp>
65 enable_if<is_convertible<
_Up*, _Tp*>::value>::type>
73 "can't delete pointer to incomplete type");
74 static_assert(
sizeof(_Tp)>0,
75 "can't delete pointer to incomplete type");
83 template<
typename _Tp>
100 enable_if<is_convertible<
_Up(*)[], _Tp(*)[]>::value>::type>
104 template<
typename _Up>
105 typename enable_if<is_convertible<
_Up(*)[], _Tp(*)[]>::value>::type
108 static_assert(
sizeof(_Tp)>0,
109 "can't delete pointer to incomplete type");
115 template <
typename _Tp,
typename _Dp = default_delete<_Tp> >
121 template<
typename _Up>
122 static typename _Up::pointer __test(
typename _Up::pointer*);
124 template<
typename _Up>
125 static _Tp* __test(...);
127 typedef typename remove_reference<_Dp>::type _Del;
137 typedef typename _Pointer::type pointer;
138 typedef _Tp element_type;
139 typedef _Dp deleter_type;
144 template<
typename _Up,
typename _Ep>
161 "constructed with null function pointer deleter"); }
175 "constructed with null function pointer deleter");
187 deleter_type,
const deleter_type&>::type __d)
noexcept
198 typename remove_reference<deleter_type>::type&& __d)
noexcept
199 : _M_t(std::move(__p), std::move(__d))
201 "rvalue deleter bound to reference"); }
206 "constructed with null function pointer deleter"); }
229#if _GLIBCXX_USE_DEPRECATED
240 if (
__ptr !=
nullptr)
268 template<
typename _Up,
typename _Ep>
269 typename enable_if< __and_<
295 __glibcxx_assert(
get() != pointer());
303 _GLIBCXX_DEBUG_PEDASSERT(
get() != pointer());
324 {
return get() == pointer() ?
false :
true; }
348 if (__p != pointer())
369 template<
typename _Tp,
typename _Dp>
375 template<
typename _Up>
376 static typename _Up::pointer __test(
typename _Up::pointer*);
378 template<
typename _Up>
379 static _Tp* __test(...);
381 typedef typename remove_reference<_Dp>::type _Del;
390 template<
typename _Up>
391 using __remove_cv =
typename remove_cv<_Up>::type;
394 template<
typename _Up>
402 typedef _Tp element_type;
403 typedef _Dp deleter_type;
407 template<
typename _Up,
typename _Ep,
421 template<
typename _Up>
440 "constructed with null function pointer deleter"); }
449 template<
typename _Up,
450 typename =
typename enable_if<
451 __safe_conversion_raw<_Up>::value,
bool>::type>
454 : _M_t(__p, deleter_type())
456 "constructed with null function pointer deleter"); }
466 template<
typename _Up,
467 typename =
typename enable_if<
468 __safe_conversion_raw<_Up>::value,
bool>::type>
471 deleter_type,
const deleter_type&>::type __d)
noexcept
482 template<
typename _Up,
483 typename =
typename enable_if<
484 __safe_conversion_raw<_Up>::value,
bool>::type>
486 remove_reference<deleter_type>::type&& __d)
noexcept
487 : _M_t(std::move(__p), std::move(__d))
489 "rvalue deleter bound to reference"); }
498 "constructed with null function pointer deleter"); }
500 template<
typename _Up,
typename _Ep,
510 if (
__ptr !=
nullptr)
538 template<
typename _Up,
typename _Ep>
605 template <
typename _Up,
623 if (
__ptr !=
nullptr)
645 template<
typename _Tp,
typename _Dp>
647 swap(unique_ptr<_Tp, _Dp>& __x,
648 unique_ptr<_Tp, _Dp>& __y)
noexcept
651 template<
typename _Tp,
typename _Dp,
652 typename _Up,
typename _Ep>
654 operator==(
const unique_ptr<_Tp, _Dp>& __x,
655 const unique_ptr<_Up, _Ep>& __y)
656 {
return __x.get() == __y.get(); }
658 template<
typename _Tp,
typename _Dp>
660 operator==(
const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
noexcept
663 template<
typename _Tp,
typename _Dp>
665 operator==(nullptr_t,
const unique_ptr<_Tp, _Dp>& __x)
noexcept
668 template<
typename _Tp,
typename _Dp,
669 typename _Up,
typename _Ep>
671 operator!=(
const unique_ptr<_Tp, _Dp>& __x,
672 const unique_ptr<_Up, _Ep>& __y)
673 {
return __x.get() != __y.get(); }
675 template<
typename _Tp,
typename _Dp>
677 operator!=(
const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
noexcept
678 {
return (
bool)__x; }
680 template<
typename _Tp,
typename _Dp>
682 operator!=(nullptr_t,
const unique_ptr<_Tp, _Dp>& __x)
noexcept
683 {
return (
bool)__x; }
685 template<
typename _Tp,
typename _Dp,
686 typename _Up,
typename _Ep>
688 operator<(
const unique_ptr<_Tp, _Dp>& __x,
689 const unique_ptr<_Up, _Ep>& __y)
693 typename unique_ptr<_Up, _Ep>::pointer>::type _CT;
697 template<
typename _Tp,
typename _Dp>
699 operator<(
const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
703 template<
typename _Tp,
typename _Dp>
705 operator<(nullptr_t,
const unique_ptr<_Tp, _Dp>& __x)
709 template<
typename _Tp,
typename _Dp,
710 typename _Up,
typename _Ep>
712 operator<=(
const unique_ptr<_Tp, _Dp>& __x,
713 const unique_ptr<_Up, _Ep>& __y)
714 {
return !(__y < __x); }
716 template<
typename _Tp,
typename _Dp>
718 operator<=(
const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
719 {
return !(
nullptr < __x); }
721 template<
typename _Tp,
typename _Dp>
723 operator<=(nullptr_t,
const unique_ptr<_Tp, _Dp>& __x)
724 {
return !(__x <
nullptr); }
726 template<
typename _Tp,
typename _Dp,
727 typename _Up,
typename _Ep>
729 operator>(
const unique_ptr<_Tp, _Dp>& __x,
730 const unique_ptr<_Up, _Ep>& __y)
731 {
return (__y < __x); }
733 template<
typename _Tp,
typename _Dp>
735 operator>(
const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
739 template<
typename _Tp,
typename _Dp>
741 operator>(nullptr_t,
const unique_ptr<_Tp, _Dp>& __x)
745 template<
typename _Tp,
typename _Dp,
746 typename _Up,
typename _Ep>
748 operator>=(
const unique_ptr<_Tp, _Dp>& __x,
749 const unique_ptr<_Up, _Ep>& __y)
750 {
return !(__x < __y); }
752 template<
typename _Tp,
typename _Dp>
754 operator>=(
const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
755 {
return !(__x <
nullptr); }
757 template<
typename _Tp,
typename _Dp>
759 operator>=(nullptr_t,
const unique_ptr<_Tp, _Dp>& __x)
760 {
return !(
nullptr < __x); }
763 template<
typename _Tp,
typename _Dp>
765 :
public __hash_base<size_t, unique_ptr<_Tp, _Dp>>
775#if __cplusplus > 201103L
777#define __cpp_lib_make_unique 201304
779 template<
typename _Tp>
783 template<
typename _Tp>
784 struct _MakeUniq<_Tp[]>
785 {
typedef unique_ptr<_Tp[]> __array; };
787 template<
typename _Tp,
size_t _Bound>
788 struct _MakeUniq<_Tp[_Bound]>
789 {
struct __invalid_type { }; };
792 template<
typename _Tp,
typename... _Args>
793 inline typename _MakeUniq<_Tp>::__single_object
798 template<
typename _Tp>
799 inline typename _MakeUniq<_Tp>::__array
804 template<
typename _Tp,
typename... _Args>
805 inline typename _MakeUniq<_Tp>::__invalid_type
811_GLIBCXX_END_NAMESPACE_VERSION
unique_ptr(_Up __p, typename conditional< is_reference< deleter_type >::value, deleter_type, const deleter_type & >::type __d) noexcept
void reset(pointer __p=pointer()) noexcept
Replace the stored pointer.
void swap(unique_ptr &__u) noexcept
Exchange the pointer and deleter with another object.
enable_if< __and_< __safe_conversion_up< _Up, _Ep >, is_assignable< deleter_type &, _Ep && > >::value, unique_ptr & >::type operator=(unique_ptr< _Up, _Ep > &&__u) noexcept
Assignment from another type.
pointer release() noexcept
Release ownership of any stored pointer.
unique_ptr(unique_ptr< _Up, _Ep > &&__u) noexcept
Converting constructor from another type.
constexpr default_delete() noexcept=default
Default constructor.
unique_ptr(unique_ptr &&__u) noexcept
Move constructor.
void reset(_Up __p) noexcept
Replace the stored pointer.
deleter_type & get_deleter() noexcept
Return a reference to the stored deleter.
_MakeUniq< _Tp >::__single_object make_unique(_Args &&... __args)
std::make_unique for single objects
constexpr unique_ptr() noexcept
Default constructor, creates a unique_ptr that owns nothing.
unique_ptr & operator=(nullptr_t) noexcept
Reset the unique_ptr to empty, invoking the deleter if necessary.
void swap(unique_ptr &__u) noexcept
Exchange the pointer and deleter with another object.
constexpr unique_ptr(nullptr_t) noexcept
Creates a unique_ptr that owns nothing.
add_lvalue_reference< element_type >::type operator*() const
Dereference the stored pointer.
enable_if< is_convertible< _Up(*)[], _Tp(*)[]>::value >::type operator()(_Up *__ptr) const
Calls delete[] __ptr.
enable_if< __and_< __safe_conversion_up< _Up, _Ep >, is_assignable< deleter_type &, _Ep && > >::value, unique_ptr & >::type operator=(unique_ptr< _Up, _Ep > &&__u) noexcept
Assignment from another type.
constexpr default_delete() noexcept=default
Default constructor.
void operator()(_Tp *__ptr) const
Calls delete __ptr.
unique_ptr & operator=(unique_ptr &&__u) noexcept
Move assignment operator.
~unique_ptr() noexcept
Destructor, invokes the deleter if the stored pointer is not null.
std::add_lvalue_reference< element_type >::type operator[](size_t __i) const
Access an element of owned array.
const deleter_type & get_deleter() const noexcept
Return a reference to the stored deleter.
constexpr unique_ptr() noexcept
Default constructor, creates a unique_ptr that owns nothing.
constexpr unique_ptr(nullptr_t) noexcept
Creates a unique_ptr that owns nothing.
unique_ptr & operator=(unique_ptr &&__u) noexcept
Move assignment operator.
unique_ptr(unique_ptr &&__u) noexcept
Move constructor.
deleter_type & get_deleter() noexcept
Return a reference to the stored deleter.
const deleter_type & get_deleter() const noexcept
Return a reference to the stored deleter.
unique_ptr(pointer __p, typename remove_reference< deleter_type >::type &&__d) noexcept
pointer operator->() const noexcept
Return the stored pointer.
unique_ptr(_Up __p, typename remove_reference< deleter_type >::type &&__d) noexcept
~unique_ptr()
Destructor, invokes the deleter if the stored pointer is not null.
unique_ptr & operator=(nullptr_t) noexcept
Reset the unique_ptr to empty, invoking the deleter if necessary.
unique_ptr(pointer __p) noexcept
pointer get() const noexcept
Return the stored pointer.
pointer get() const noexcept
Return the stored pointer.
unique_ptr(pointer __p, typename conditional< is_reference< deleter_type >::value, deleter_type, const deleter_type & >::type __d) noexcept
pointer release() noexcept
Release ownership of any stored pointer.
unique_ptr(_Up __p) noexcept
ISO C++ entities toplevel namespace is std.
Primary class template hash.
Primary template of default_delete, used by unique_ptr.
20.7.1.2 unique_ptr for single objects.