libstdc++
unique_ptr.h
Go to the documentation of this file.
1// unique_ptr implementation -*- C++ -*-
2
3// Copyright (C) 2008-2022 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/** @file bits/unique_ptr.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{memory}
28 */
29
30#ifndef _UNIQUE_PTR_H
31#define _UNIQUE_PTR_H 1
32
33#include <bits/c++config.h>
34#include <debug/assertions.h>
35#include <type_traits>
36#include <tuple>
37#include <bits/stl_function.h>
39#if __cplusplus >= 202002L
40# include <compare>
41# if _GLIBCXX_HOSTED
42# include <ostream>
43# endif
44#endif
45
46#if __cplusplus > 202002L && __cpp_constexpr_dynamic_alloc
47# if __cpp_lib_constexpr_memory < 202202L
48// Defined with older value in bits/ptr_traits.h for C++20
49# undef __cpp_lib_constexpr_memory
50# define __cpp_lib_constexpr_memory 202202L
51# endif
52#endif
53
54namespace std _GLIBCXX_VISIBILITY(default)
55{
56_GLIBCXX_BEGIN_NAMESPACE_VERSION
57
58 /**
59 * @addtogroup pointer_abstractions
60 * @{
61 */
62
63#if _GLIBCXX_USE_DEPRECATED
64#pragma GCC diagnostic push
65#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
66 template<typename> class auto_ptr;
67#pragma GCC diagnostic pop
68#endif
69
70 /** Primary template of default_delete, used by unique_ptr for single objects
71 *
72 * @headerfile memory
73 * @since C++11
74 */
75 template<typename _Tp>
77 {
78 /// Default constructor
79 constexpr default_delete() noexcept = default;
80
81 /** @brief Converting constructor.
82 *
83 * Allows conversion from a deleter for objects of another type, `_Up`,
84 * only if `_Up*` is convertible to `_Tp*`.
85 */
86 template<typename _Up,
87 typename = _Require<is_convertible<_Up*, _Tp*>>>
88 _GLIBCXX23_CONSTEXPR
89 default_delete(const default_delete<_Up>&) noexcept { }
90
91 /// Calls `delete __ptr`
92 _GLIBCXX23_CONSTEXPR
93 void
94 operator()(_Tp* __ptr) const
95 {
96 static_assert(!is_void<_Tp>::value,
97 "can't delete pointer to incomplete type");
98 static_assert(sizeof(_Tp)>0,
99 "can't delete pointer to incomplete type");
100 delete __ptr;
101 }
102 };
103
104 // _GLIBCXX_RESOLVE_LIB_DEFECTS
105 // DR 740 - omit specialization for array objects with a compile time length
106
107 /** Specialization of default_delete for arrays, used by `unique_ptr<T[]>`
108 *
109 * @headerfile memory
110 * @since C++11
111 */
112 template<typename _Tp>
113 struct default_delete<_Tp[]>
114 {
115 public:
116 /// Default constructor
117 constexpr default_delete() noexcept = default;
118
119 /** @brief Converting constructor.
120 *
121 * Allows conversion from a deleter for arrays of another type, such as
122 * a const-qualified version of `_Tp`.
123 *
124 * Conversions from types derived from `_Tp` are not allowed because
125 * it is undefined to `delete[]` an array of derived types through a
126 * pointer to the base type.
127 */
128 template<typename _Up,
129 typename = _Require<is_convertible<_Up(*)[], _Tp(*)[]>>>
130 _GLIBCXX23_CONSTEXPR
131 default_delete(const default_delete<_Up[]>&) noexcept { }
132
133 /// Calls `delete[] __ptr`
134 template<typename _Up>
135 _GLIBCXX23_CONSTEXPR
136 typename enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value>::type
137 operator()(_Up* __ptr) const
138 {
139 static_assert(sizeof(_Tp)>0,
140 "can't delete pointer to incomplete type");
141 delete [] __ptr;
142 }
143 };
144
145 /// @cond undocumented
146
147 // Manages the pointer and deleter of a unique_ptr
148 template <typename _Tp, typename _Dp>
149 class __uniq_ptr_impl
150 {
151 template <typename _Up, typename _Ep, typename = void>
152 struct _Ptr
153 {
154 using type = _Up*;
155 };
156
157 template <typename _Up, typename _Ep>
158 struct
159 _Ptr<_Up, _Ep, __void_t<typename remove_reference<_Ep>::type::pointer>>
160 {
161 using type = typename remove_reference<_Ep>::type::pointer;
162 };
163
164 public:
165 using _DeleterConstraint = enable_if<
166 __and_<__not_<is_pointer<_Dp>>,
167 is_default_constructible<_Dp>>::value>;
168
169 using pointer = typename _Ptr<_Tp, _Dp>::type;
170
171 static_assert( !is_rvalue_reference<_Dp>::value,
172 "unique_ptr's deleter type must be a function object type"
173 " or an lvalue reference type" );
174
175 __uniq_ptr_impl() = default;
176 _GLIBCXX23_CONSTEXPR
177 __uniq_ptr_impl(pointer __p) : _M_t() { _M_ptr() = __p; }
178
179 template<typename _Del>
180 _GLIBCXX23_CONSTEXPR
181 __uniq_ptr_impl(pointer __p, _Del&& __d)
182 : _M_t(__p, std::forward<_Del>(__d)) { }
183
184 _GLIBCXX23_CONSTEXPR
185 __uniq_ptr_impl(__uniq_ptr_impl&& __u) noexcept
186 : _M_t(std::move(__u._M_t))
187 { __u._M_ptr() = nullptr; }
188
189 _GLIBCXX23_CONSTEXPR
190 __uniq_ptr_impl& operator=(__uniq_ptr_impl&& __u) noexcept
191 {
192 reset(__u.release());
193 _M_deleter() = std::forward<_Dp>(__u._M_deleter());
194 return *this;
195 }
196
197 _GLIBCXX23_CONSTEXPR
198 pointer& _M_ptr() noexcept { return std::get<0>(_M_t); }
199 _GLIBCXX23_CONSTEXPR
200 pointer _M_ptr() const noexcept { return std::get<0>(_M_t); }
201 _GLIBCXX23_CONSTEXPR
202 _Dp& _M_deleter() noexcept { return std::get<1>(_M_t); }
203 _GLIBCXX23_CONSTEXPR
204 const _Dp& _M_deleter() const noexcept { return std::get<1>(_M_t); }
205
206 _GLIBCXX23_CONSTEXPR
207 void reset(pointer __p) noexcept
208 {
209 const pointer __old_p = _M_ptr();
210 _M_ptr() = __p;
211 if (__old_p)
212 _M_deleter()(__old_p);
213 }
214
215 _GLIBCXX23_CONSTEXPR
216 pointer release() noexcept
217 {
218 pointer __p = _M_ptr();
219 _M_ptr() = nullptr;
220 return __p;
221 }
222
223 _GLIBCXX23_CONSTEXPR
224 void
225 swap(__uniq_ptr_impl& __rhs) noexcept
226 {
227 using std::swap;
228 swap(this->_M_ptr(), __rhs._M_ptr());
229 swap(this->_M_deleter(), __rhs._M_deleter());
230 }
231
232 private:
233 tuple<pointer, _Dp> _M_t;
234 };
235
236 // Defines move construction + assignment as either defaulted or deleted.
237 template <typename _Tp, typename _Dp,
238 bool = is_move_constructible<_Dp>::value,
239 bool = is_move_assignable<_Dp>::value>
240 struct __uniq_ptr_data : __uniq_ptr_impl<_Tp, _Dp>
241 {
242 using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl;
243 __uniq_ptr_data(__uniq_ptr_data&&) = default;
244 __uniq_ptr_data& operator=(__uniq_ptr_data&&) = default;
245 };
246
247 template <typename _Tp, typename _Dp>
248 struct __uniq_ptr_data<_Tp, _Dp, true, false> : __uniq_ptr_impl<_Tp, _Dp>
249 {
250 using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl;
251 __uniq_ptr_data(__uniq_ptr_data&&) = default;
252 __uniq_ptr_data& operator=(__uniq_ptr_data&&) = delete;
253 };
254
255 template <typename _Tp, typename _Dp>
256 struct __uniq_ptr_data<_Tp, _Dp, false, true> : __uniq_ptr_impl<_Tp, _Dp>
257 {
258 using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl;
259 __uniq_ptr_data(__uniq_ptr_data&&) = delete;
260 __uniq_ptr_data& operator=(__uniq_ptr_data&&) = default;
261 };
262
263 template <typename _Tp, typename _Dp>
264 struct __uniq_ptr_data<_Tp, _Dp, false, false> : __uniq_ptr_impl<_Tp, _Dp>
265 {
266 using __uniq_ptr_impl<_Tp, _Dp>::__uniq_ptr_impl;
267 __uniq_ptr_data(__uniq_ptr_data&&) = delete;
268 __uniq_ptr_data& operator=(__uniq_ptr_data&&) = delete;
269 };
270 /// @endcond
271
272 // 20.7.1.2 unique_ptr for single objects.
273
274 /// A move-only smart pointer that manages unique ownership of a resource.
275 /// @headerfile memory
276 /// @since C++11
277 template <typename _Tp, typename _Dp = default_delete<_Tp>>
279 {
280 template <typename _Up>
281 using _DeleterConstraint =
282 typename __uniq_ptr_impl<_Tp, _Up>::_DeleterConstraint::type;
283
284 __uniq_ptr_data<_Tp, _Dp> _M_t;
285
286 public:
287 using pointer = typename __uniq_ptr_impl<_Tp, _Dp>::pointer;
288 using element_type = _Tp;
289 using deleter_type = _Dp;
290
291 private:
292 // helper template for detecting a safe conversion from another
293 // unique_ptr
294 template<typename _Up, typename _Ep>
295 using __safe_conversion_up = __and_<
296 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>,
297 __not_<is_array<_Up>>
298 >;
299
300 public:
301 // Constructors.
302
303 /// Default constructor, creates a unique_ptr that owns nothing.
304 template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>>
305 constexpr unique_ptr() noexcept
306 : _M_t()
307 { }
308
309 /** Takes ownership of a pointer.
310 *
311 * @param __p A pointer to an object of @c element_type
312 *
313 * The deleter will be value-initialized.
314 */
315 template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>>
316 _GLIBCXX23_CONSTEXPR
317 explicit
318 unique_ptr(pointer __p) noexcept
319 : _M_t(__p)
320 { }
321
322 /** Takes ownership of a pointer.
323 *
324 * @param __p A pointer to an object of @c element_type
325 * @param __d A reference to a deleter.
326 *
327 * The deleter will be initialized with @p __d
328 */
329 template<typename _Del = deleter_type,
330 typename = _Require<is_copy_constructible<_Del>>>
331 _GLIBCXX23_CONSTEXPR
332 unique_ptr(pointer __p, const deleter_type& __d) noexcept
333 : _M_t(__p, __d) { }
334
335 /** Takes ownership of a pointer.
336 *
337 * @param __p A pointer to an object of @c element_type
338 * @param __d An rvalue reference to a (non-reference) deleter.
339 *
340 * The deleter will be initialized with @p std::move(__d)
341 */
342 template<typename _Del = deleter_type,
343 typename = _Require<is_move_constructible<_Del>>>
344 _GLIBCXX23_CONSTEXPR
345 unique_ptr(pointer __p,
347 _Del&&> __d) noexcept
348 : _M_t(__p, std::move(__d))
349 { }
350
351 template<typename _Del = deleter_type,
352 typename _DelUnref = typename remove_reference<_Del>::type>
353 _GLIBCXX23_CONSTEXPR
354 unique_ptr(pointer,
356 _DelUnref&&>) = delete;
357
358 /// Creates a unique_ptr that owns nothing.
359 template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>>
360 constexpr unique_ptr(nullptr_t) noexcept
361 : _M_t()
362 { }
363
364 // Move constructors.
365
366 /// Move constructor.
367 unique_ptr(unique_ptr&&) = default;
368
369 /** @brief Converting constructor from another type
370 *
371 * Requires that the pointer owned by @p __u is convertible to the
372 * type of pointer owned by this object, @p __u does not own an array,
373 * and @p __u has a compatible deleter type.
374 */
375 template<typename _Up, typename _Ep, typename = _Require<
376 __safe_conversion_up<_Up, _Ep>,
377 __conditional_t<is_reference<_Dp>::value,
379 is_convertible<_Ep, _Dp>>>>
380 _GLIBCXX23_CONSTEXPR
382 : _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter()))
383 { }
384
385#if _GLIBCXX_USE_DEPRECATED
386#pragma GCC diagnostic push
387#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
388 /// Converting constructor from @c auto_ptr
389 template<typename _Up, typename = _Require<
390 is_convertible<_Up*, _Tp*>, is_same<_Dp, default_delete<_Tp>>>>
391 unique_ptr(auto_ptr<_Up>&& __u) noexcept;
392#pragma GCC diagnostic pop
393#endif
394
395 /// Destructor, invokes the deleter if the stored pointer is not null.
396#if __cplusplus > 202002L && __cpp_constexpr_dynamic_alloc
397 constexpr
398#endif
399 ~unique_ptr() noexcept
400 {
401 static_assert(__is_invocable<deleter_type&, pointer>::value,
402 "unique_ptr's deleter must be invocable with a pointer");
403 auto& __ptr = _M_t._M_ptr();
404 if (__ptr != nullptr)
405 get_deleter()(std::move(__ptr));
406 __ptr = pointer();
407 }
408
409 // Assignment.
410
411 /** @brief Move assignment operator.
412 *
413 * Invokes the deleter if this object owns a pointer.
414 */
416
417 /** @brief Assignment from another type.
418 *
419 * @param __u The object to transfer ownership from, which owns a
420 * convertible pointer to a non-array object.
421 *
422 * Invokes the deleter if this object owns a pointer.
423 */
424 template<typename _Up, typename _Ep>
425 _GLIBCXX23_CONSTEXPR
426 typename enable_if< __and_<
427 __safe_conversion_up<_Up, _Ep>,
429 >::value,
430 unique_ptr&>::type
432 {
433 reset(__u.release());
434 get_deleter() = std::forward<_Ep>(__u.get_deleter());
435 return *this;
436 }
437
438 /// Reset the %unique_ptr to empty, invoking the deleter if necessary.
439 _GLIBCXX23_CONSTEXPR
441 operator=(nullptr_t) noexcept
442 {
443 reset();
444 return *this;
445 }
446
447 // Observers.
448
449 /// Dereference the stored pointer.
450 _GLIBCXX23_CONSTEXPR
451 typename add_lvalue_reference<element_type>::type
452 operator*() const noexcept(noexcept(*std::declval<pointer>()))
453 {
454 __glibcxx_assert(get() != pointer());
455 return *get();
456 }
457
458 /// Return the stored pointer.
459 _GLIBCXX23_CONSTEXPR
460 pointer
461 operator->() const noexcept
462 {
463 _GLIBCXX_DEBUG_PEDASSERT(get() != pointer());
464 return get();
465 }
466
467 /// Return the stored pointer.
468 _GLIBCXX23_CONSTEXPR
469 pointer
470 get() const noexcept
471 { return _M_t._M_ptr(); }
472
473 /// Return a reference to the stored deleter.
474 _GLIBCXX23_CONSTEXPR
475 deleter_type&
476 get_deleter() noexcept
477 { return _M_t._M_deleter(); }
478
479 /// Return a reference to the stored deleter.
480 _GLIBCXX23_CONSTEXPR
481 const deleter_type&
482 get_deleter() const noexcept
483 { return _M_t._M_deleter(); }
484
485 /// Return @c true if the stored pointer is not null.
486 _GLIBCXX23_CONSTEXPR
487 explicit operator bool() const noexcept
488 { return get() == pointer() ? false : true; }
489
490 // Modifiers.
491
492 /// Release ownership of any stored pointer.
493 _GLIBCXX23_CONSTEXPR
494 pointer
495 release() noexcept
496 { return _M_t.release(); }
497
498 /** @brief Replace the stored pointer.
499 *
500 * @param __p The new pointer to store.
501 *
502 * The deleter will be invoked if a pointer is already owned.
503 */
504 _GLIBCXX23_CONSTEXPR
505 void
506 reset(pointer __p = pointer()) noexcept
507 {
508 static_assert(__is_invocable<deleter_type&, pointer>::value,
509 "unique_ptr's deleter must be invocable with a pointer");
510 _M_t.reset(std::move(__p));
511 }
512
513 /// Exchange the pointer and deleter with another object.
514 _GLIBCXX23_CONSTEXPR
515 void
516 swap(unique_ptr& __u) noexcept
517 {
518 static_assert(__is_swappable<_Dp>::value, "deleter must be swappable");
519 _M_t.swap(__u._M_t);
520 }
521
522 // Disable copy from lvalue.
523 unique_ptr(const unique_ptr&) = delete;
524 unique_ptr& operator=(const unique_ptr&) = delete;
525 };
526
527 // 20.7.1.3 unique_ptr for array objects with a runtime length
528 // [unique.ptr.runtime]
529 // _GLIBCXX_RESOLVE_LIB_DEFECTS
530 // DR 740 - omit specialization for array objects with a compile time length
531
532 /// A move-only smart pointer that manages unique ownership of an array.
533 /// @headerfile memory
534 /// @since C++11
535 template<typename _Tp, typename _Dp>
536 class unique_ptr<_Tp[], _Dp>
537 {
538 template <typename _Up>
539 using _DeleterConstraint =
540 typename __uniq_ptr_impl<_Tp, _Up>::_DeleterConstraint::type;
541
542 __uniq_ptr_data<_Tp, _Dp> _M_t;
543
544 // like is_base_of<_Tp, _Up> but false if unqualified types are the same
545 template<typename _Up>
546 using __is_derived_Tp
547 = __and_< is_base_of<_Tp, _Up>,
548 __not_<is_same<__remove_cv_t<_Tp>, __remove_cv_t<_Up>>> >;
549
550 public:
551 using pointer = typename __uniq_ptr_impl<_Tp, _Dp>::pointer;
552 using element_type = _Tp;
553 using deleter_type = _Dp;
554
555 // helper template for detecting a safe conversion from another
556 // unique_ptr
557 template<typename _Up, typename _Ep,
558 typename _UPtr = unique_ptr<_Up, _Ep>,
559 typename _UP_pointer = typename _UPtr::pointer,
560 typename _UP_element_type = typename _UPtr::element_type>
561 using __safe_conversion_up = __and_<
565 is_convertible<_UP_element_type(*)[], element_type(*)[]>
566 >;
567
568 // helper template for detecting a safe conversion from a raw pointer
569 template<typename _Up>
570 using __safe_conversion_raw = __and_<
571 __or_<__or_<is_same<_Up, pointer>,
573 __and_<is_pointer<_Up>,
575 is_convertible<
576 typename remove_pointer<_Up>::type(*)[],
577 element_type(*)[]>
578 >
579 >
580 >;
581
582 // Constructors.
583
584 /// Default constructor, creates a unique_ptr that owns nothing.
585 template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>>
586 constexpr unique_ptr() noexcept
587 : _M_t()
588 { }
589
590 /** Takes ownership of a pointer.
591 *
592 * @param __p A pointer to an array of a type safely convertible
593 * to an array of @c element_type
594 *
595 * The deleter will be value-initialized.
596 */
597 template<typename _Up,
598 typename _Vp = _Dp,
599 typename = _DeleterConstraint<_Vp>,
600 typename = typename enable_if<
601 __safe_conversion_raw<_Up>::value, bool>::type>
602 _GLIBCXX23_CONSTEXPR
603 explicit
604 unique_ptr(_Up __p) noexcept
605 : _M_t(__p)
606 { }
607
608 /** Takes ownership of a pointer.
609 *
610 * @param __p A pointer to an array of a type safely convertible
611 * to an array of @c element_type
612 * @param __d A reference to a deleter.
613 *
614 * The deleter will be initialized with @p __d
615 */
616 template<typename _Up, typename _Del = deleter_type,
617 typename = _Require<__safe_conversion_raw<_Up>,
619 _GLIBCXX23_CONSTEXPR
620 unique_ptr(_Up __p, const deleter_type& __d) noexcept
621 : _M_t(__p, __d) { }
622
623 /** Takes ownership of a pointer.
624 *
625 * @param __p A pointer to an array of a type safely convertible
626 * to an array of @c element_type
627 * @param __d A reference to a deleter.
628 *
629 * The deleter will be initialized with @p std::move(__d)
630 */
631 template<typename _Up, typename _Del = deleter_type,
632 typename = _Require<__safe_conversion_raw<_Up>,
634 _GLIBCXX23_CONSTEXPR
635 unique_ptr(_Up __p,
637 _Del&&> __d) noexcept
638 : _M_t(std::move(__p), std::move(__d))
639 { }
640
641 template<typename _Up, typename _Del = deleter_type,
642 typename _DelUnref = typename remove_reference<_Del>::type,
643 typename = _Require<__safe_conversion_raw<_Up>>>
644 unique_ptr(_Up,
646 _DelUnref&&>) = delete;
647
648 /// Move constructor.
649 unique_ptr(unique_ptr&&) = default;
650
651 /// Creates a unique_ptr that owns nothing.
652 template<typename _Del = _Dp, typename = _DeleterConstraint<_Del>>
653 constexpr unique_ptr(nullptr_t) noexcept
654 : _M_t()
655 { }
656
657 template<typename _Up, typename _Ep, typename = _Require<
658 __safe_conversion_up<_Up, _Ep>,
659 __conditional_t<is_reference<_Dp>::value,
661 is_convertible<_Ep, _Dp>>>>
662 _GLIBCXX23_CONSTEXPR
663 unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
664 : _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter()))
665 { }
666
667 /// Destructor, invokes the deleter if the stored pointer is not null.
668#if __cplusplus > 202002L && __cpp_constexpr_dynamic_alloc
669 constexpr
670#endif
672 {
673 auto& __ptr = _M_t._M_ptr();
674 if (__ptr != nullptr)
675 get_deleter()(__ptr);
676 __ptr = pointer();
677 }
678
679 // Assignment.
680
681 /** @brief Move assignment operator.
682 *
683 * Invokes the deleter if this object owns a pointer.
684 */
686 operator=(unique_ptr&&) = default;
687
688 /** @brief Assignment from another type.
689 *
690 * @param __u The object to transfer ownership from, which owns a
691 * convertible pointer to an array object.
692 *
693 * Invokes the deleter if this object owns a pointer.
694 */
695 template<typename _Up, typename _Ep>
696 _GLIBCXX23_CONSTEXPR
697 typename
700 >::value,
701 unique_ptr&>::type
703 {
704 reset(__u.release());
705 get_deleter() = std::forward<_Ep>(__u.get_deleter());
706 return *this;
707 }
708
709 /// Reset the %unique_ptr to empty, invoking the deleter if necessary.
710 _GLIBCXX23_CONSTEXPR
712 operator=(nullptr_t) noexcept
713 {
714 reset();
715 return *this;
716 }
717
718 // Observers.
719
720 /// Access an element of owned array.
721 _GLIBCXX23_CONSTEXPR
722 typename std::add_lvalue_reference<element_type>::type
723 operator[](size_t __i) const
724 {
725 __glibcxx_assert(get() != pointer());
726 return get()[__i];
727 }
728
729 /// Return the stored pointer.
730 _GLIBCXX23_CONSTEXPR
731 pointer
732 get() const noexcept
733 { return _M_t._M_ptr(); }
734
735 /// Return a reference to the stored deleter.
736 _GLIBCXX23_CONSTEXPR
737 deleter_type&
738 get_deleter() noexcept
739 { return _M_t._M_deleter(); }
740
741 /// Return a reference to the stored deleter.
742 _GLIBCXX23_CONSTEXPR
743 const deleter_type&
744 get_deleter() const noexcept
745 { return _M_t._M_deleter(); }
746
747 /// Return @c true if the stored pointer is not null.
748 _GLIBCXX23_CONSTEXPR
749 explicit operator bool() const noexcept
750 { return get() == pointer() ? false : true; }
751
752 // Modifiers.
753
754 /// Release ownership of any stored pointer.
755 _GLIBCXX23_CONSTEXPR
756 pointer
757 release() noexcept
758 { return _M_t.release(); }
759
760 /** @brief Replace the stored pointer.
761 *
762 * @param __p The new pointer to store.
763 *
764 * The deleter will be invoked if a pointer is already owned.
765 */
766 template <typename _Up,
767 typename = _Require<
768 __or_<is_same<_Up, pointer>,
769 __and_<is_same<pointer, element_type*>,
771 is_convertible<
772 typename remove_pointer<_Up>::type(*)[],
773 element_type(*)[]
774 >
775 >
776 >
777 >>
778 _GLIBCXX23_CONSTEXPR
779 void
780 reset(_Up __p) noexcept
781 { _M_t.reset(std::move(__p)); }
782
783 _GLIBCXX23_CONSTEXPR
784 void reset(nullptr_t = nullptr) noexcept
785 { reset(pointer()); }
786
787 /// Exchange the pointer and deleter with another object.
788 _GLIBCXX23_CONSTEXPR
789 void
790 swap(unique_ptr& __u) noexcept
791 {
792 static_assert(__is_swappable<_Dp>::value, "deleter must be swappable");
793 _M_t.swap(__u._M_t);
794 }
795
796 // Disable copy from lvalue.
797 unique_ptr(const unique_ptr&) = delete;
798 unique_ptr& operator=(const unique_ptr&) = delete;
799 };
800
801 /// @{
802 /// @relates unique_ptr
803
804 /// Swap overload for unique_ptr
805 template<typename _Tp, typename _Dp>
806 inline
807#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
808 // Constrained free swap overload, see p0185r1
809 _GLIBCXX23_CONSTEXPR
810 typename enable_if<__is_swappable<_Dp>::value>::type
811#else
812 void
813#endif
815 unique_ptr<_Tp, _Dp>& __y) noexcept
816 { __x.swap(__y); }
817
818#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
819 template<typename _Tp, typename _Dp>
822 unique_ptr<_Tp, _Dp>&) = delete;
823#endif
824
825 /// Equality operator for unique_ptr objects, compares the owned pointers
826 template<typename _Tp, typename _Dp,
827 typename _Up, typename _Ep>
828 _GLIBCXX_NODISCARD _GLIBCXX23_CONSTEXPR
829 inline bool
830 operator==(const unique_ptr<_Tp, _Dp>& __x,
831 const unique_ptr<_Up, _Ep>& __y)
832 { return __x.get() == __y.get(); }
833
834 /// unique_ptr comparison with nullptr
835 template<typename _Tp, typename _Dp>
836 _GLIBCXX_NODISCARD _GLIBCXX23_CONSTEXPR
837 inline bool
838 operator==(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept
839 { return !__x; }
840
841#ifndef __cpp_lib_three_way_comparison
842 /// unique_ptr comparison with nullptr
843 template<typename _Tp, typename _Dp>
844 _GLIBCXX_NODISCARD
845 inline bool
846 operator==(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept
847 { return !__x; }
848
849 /// Inequality operator for unique_ptr objects, compares the owned pointers
850 template<typename _Tp, typename _Dp,
851 typename _Up, typename _Ep>
852 _GLIBCXX_NODISCARD
853 inline bool
854 operator!=(const unique_ptr<_Tp, _Dp>& __x,
855 const unique_ptr<_Up, _Ep>& __y)
856 { return __x.get() != __y.get(); }
857
858 /// unique_ptr comparison with nullptr
859 template<typename _Tp, typename _Dp>
860 _GLIBCXX_NODISCARD
861 inline bool
862 operator!=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) noexcept
863 { return (bool)__x; }
864
865 /// unique_ptr comparison with nullptr
866 template<typename _Tp, typename _Dp>
867 _GLIBCXX_NODISCARD
868 inline bool
869 operator!=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) noexcept
870 { return (bool)__x; }
871#endif // three way comparison
872
873 /// Relational operator for unique_ptr objects, compares the owned pointers
874 template<typename _Tp, typename _Dp,
875 typename _Up, typename _Ep>
876 _GLIBCXX_NODISCARD _GLIBCXX23_CONSTEXPR
877 inline bool
878 operator<(const unique_ptr<_Tp, _Dp>& __x,
879 const unique_ptr<_Up, _Ep>& __y)
880 {
881 typedef typename
883 typename unique_ptr<_Up, _Ep>::pointer>::type _CT;
884 return std::less<_CT>()(__x.get(), __y.get());
885 }
886
887 /// unique_ptr comparison with nullptr
888 template<typename _Tp, typename _Dp>
889 _GLIBCXX_NODISCARD _GLIBCXX23_CONSTEXPR
890 inline bool
891 operator<(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
892 {
894 nullptr);
895 }
896
897 /// unique_ptr comparison with nullptr
898 template<typename _Tp, typename _Dp>
899 _GLIBCXX_NODISCARD _GLIBCXX23_CONSTEXPR
900 inline bool
901 operator<(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
902 {
904 __x.get());
905 }
906
907 /// Relational operator for unique_ptr objects, compares the owned pointers
908 template<typename _Tp, typename _Dp,
909 typename _Up, typename _Ep>
910 _GLIBCXX_NODISCARD _GLIBCXX23_CONSTEXPR
911 inline bool
912 operator<=(const unique_ptr<_Tp, _Dp>& __x,
913 const unique_ptr<_Up, _Ep>& __y)
914 { return !(__y < __x); }
915
916 /// unique_ptr comparison with nullptr
917 template<typename _Tp, typename _Dp>
918 _GLIBCXX_NODISCARD _GLIBCXX23_CONSTEXPR
919 inline bool
920 operator<=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
921 { return !(nullptr < __x); }
922
923 /// unique_ptr comparison with nullptr
924 template<typename _Tp, typename _Dp>
925 _GLIBCXX_NODISCARD _GLIBCXX23_CONSTEXPR
926 inline bool
927 operator<=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
928 { return !(__x < nullptr); }
929
930 /// Relational operator for unique_ptr objects, compares the owned pointers
931 template<typename _Tp, typename _Dp,
932 typename _Up, typename _Ep>
933 _GLIBCXX_NODISCARD _GLIBCXX23_CONSTEXPR
934 inline bool
935 operator>(const unique_ptr<_Tp, _Dp>& __x,
936 const unique_ptr<_Up, _Ep>& __y)
937 { return (__y < __x); }
938
939 /// unique_ptr comparison with nullptr
940 template<typename _Tp, typename _Dp>
941 _GLIBCXX_NODISCARD _GLIBCXX23_CONSTEXPR
942 inline bool
943 operator>(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
944 {
946 __x.get());
947 }
948
949 /// unique_ptr comparison with nullptr
950 template<typename _Tp, typename _Dp>
951 _GLIBCXX_NODISCARD _GLIBCXX23_CONSTEXPR
952 inline bool
953 operator>(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
954 {
956 nullptr);
957 }
958
959 /// Relational operator for unique_ptr objects, compares the owned pointers
960 template<typename _Tp, typename _Dp,
961 typename _Up, typename _Ep>
962 _GLIBCXX_NODISCARD _GLIBCXX23_CONSTEXPR
963 inline bool
964 operator>=(const unique_ptr<_Tp, _Dp>& __x,
965 const unique_ptr<_Up, _Ep>& __y)
966 { return !(__x < __y); }
967
968 /// unique_ptr comparison with nullptr
969 template<typename _Tp, typename _Dp>
970 _GLIBCXX_NODISCARD _GLIBCXX23_CONSTEXPR
971 inline bool
972 operator>=(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
973 { return !(__x < nullptr); }
974
975 /// unique_ptr comparison with nullptr
976 template<typename _Tp, typename _Dp>
977 _GLIBCXX_NODISCARD inline bool
978 operator>=(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
979 { return !(nullptr < __x); }
980
981#ifdef __cpp_lib_three_way_comparison
982 template<typename _Tp, typename _Dp, typename _Up, typename _Ep>
983 requires three_way_comparable_with<typename unique_ptr<_Tp, _Dp>::pointer,
984 typename unique_ptr<_Up, _Ep>::pointer>
985 _GLIBCXX23_CONSTEXPR
986 inline
987 compare_three_way_result_t<typename unique_ptr<_Tp, _Dp>::pointer,
988 typename unique_ptr<_Up, _Ep>::pointer>
989 operator<=>(const unique_ptr<_Tp, _Dp>& __x,
990 const unique_ptr<_Up, _Ep>& __y)
991 { return compare_three_way()(__x.get(), __y.get()); }
992
993 template<typename _Tp, typename _Dp>
994 requires three_way_comparable<typename unique_ptr<_Tp, _Dp>::pointer>
995 _GLIBCXX23_CONSTEXPR
996 inline
997 compare_three_way_result_t<typename unique_ptr<_Tp, _Dp>::pointer>
998 operator<=>(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
999 {
1000 using pointer = typename unique_ptr<_Tp, _Dp>::pointer;
1001 return compare_three_way()(__x.get(), static_cast<pointer>(nullptr));
1002 }
1003#endif
1004 /// @} relates unique_ptr
1005
1006 /// @cond undocumented
1007 template<typename _Up, typename _Ptr = typename _Up::pointer,
1008 bool = __poison_hash<_Ptr>::__enable_hash_call>
1009 struct __uniq_ptr_hash
1010#if ! _GLIBCXX_INLINE_VERSION
1011 : private __poison_hash<_Ptr>
1012#endif
1013 {
1014 size_t
1015 operator()(const _Up& __u) const
1016 noexcept(noexcept(std::declval<hash<_Ptr>>()(std::declval<_Ptr>())))
1017 { return hash<_Ptr>()(__u.get()); }
1018 };
1019
1020 template<typename _Up, typename _Ptr>
1021 struct __uniq_ptr_hash<_Up, _Ptr, false>
1022 : private __poison_hash<_Ptr>
1023 { };
1024 /// @endcond
1025
1026 /// std::hash specialization for unique_ptr.
1027 template<typename _Tp, typename _Dp>
1028 struct hash<unique_ptr<_Tp, _Dp>>
1029 : public __hash_base<size_t, unique_ptr<_Tp, _Dp>>,
1030 public __uniq_ptr_hash<unique_ptr<_Tp, _Dp>>
1031 { };
1032
1033#if __cplusplus >= 201402L && _GLIBCXX_HOSTED
1034#define __cpp_lib_make_unique 201304L
1035
1036 /// @cond undocumented
1037namespace __detail
1038{
1039 template<typename _Tp>
1040 struct _MakeUniq
1041 { typedef unique_ptr<_Tp> __single_object; };
1042
1043 template<typename _Tp>
1044 struct _MakeUniq<_Tp[]>
1045 { typedef unique_ptr<_Tp[]> __array; };
1046
1047 template<typename _Tp, size_t _Bound>
1048 struct _MakeUniq<_Tp[_Bound]>
1049 { struct __invalid_type { }; };
1050
1051 template<typename _Tp>
1052 using __unique_ptr_t = typename _MakeUniq<_Tp>::__single_object;
1053 template<typename _Tp>
1054 using __unique_ptr_array_t = typename _MakeUniq<_Tp>::__array;
1055 template<typename _Tp>
1056 using __invalid_make_unique_t = typename _MakeUniq<_Tp>::__invalid_type;
1057}
1058 /// @endcond
1059
1060 /** Create an object owned by a `unique_ptr`.
1061 * @tparam _Tp A non-array object type.
1062 * @param __args Constructor arguments for the new object.
1063 * @returns A `unique_ptr<_Tp>` that owns the new object.
1064 * @since C++14
1065 * @relates unique_ptr
1066 */
1067 template<typename _Tp, typename... _Args>
1068 _GLIBCXX23_CONSTEXPR
1069 inline __detail::__unique_ptr_t<_Tp>
1070 make_unique(_Args&&... __args)
1071 { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }
1072
1073 /** Create an array owned by a `unique_ptr`.
1074 * @tparam _Tp An array type of unknown bound, such as `U[]`.
1075 * @param __num The number of elements of type `U` in the new array.
1076 * @returns A `unique_ptr<U[]>` that owns the new array.
1077 * @since C++14
1078 * @relates unique_ptr
1079 *
1080 * The array elements are value-initialized.
1081 */
1082 template<typename _Tp>
1083 _GLIBCXX23_CONSTEXPR
1084 inline __detail::__unique_ptr_array_t<_Tp>
1085 make_unique(size_t __num)
1086 { return unique_ptr<_Tp>(new remove_extent_t<_Tp>[__num]()); }
1087
1088 /** Disable std::make_unique for arrays of known bound.
1089 * @tparam _Tp An array type of known bound, such as `U[N]`.
1090 * @since C++14
1091 * @relates unique_ptr
1092 */
1093 template<typename _Tp, typename... _Args>
1094 __detail::__invalid_make_unique_t<_Tp>
1095 make_unique(_Args&&...) = delete;
1096
1097#if __cplusplus > 201703L
1098 /** Create a default-initialied object owned by a `unique_ptr`.
1099 * @tparam _Tp A non-array object type.
1100 * @returns A `unique_ptr<_Tp>` that owns the new object.
1101 * @since C++20
1102 * @relates unique_ptr
1103 */
1104 template<typename _Tp>
1105 _GLIBCXX23_CONSTEXPR
1106 inline __detail::__unique_ptr_t<_Tp>
1108 { return unique_ptr<_Tp>(new _Tp); }
1109
1110 /** Create a default-initialized array owned by a `unique_ptr`.
1111 * @tparam _Tp An array type of unknown bound, such as `U[]`.
1112 * @param __num The number of elements of type `U` in the new array.
1113 * @returns A `unique_ptr<U[]>` that owns the new array.
1114 * @since C++20
1115 * @relates unique_ptr
1116 */
1117 template<typename _Tp>
1118 _GLIBCXX23_CONSTEXPR
1119 inline __detail::__unique_ptr_array_t<_Tp>
1121 { return unique_ptr<_Tp>(new remove_extent_t<_Tp>[__num]); }
1122
1123 /** Disable std::make_unique_for_overwrite for arrays of known bound.
1124 * @tparam _Tp An array type of known bound, such as `U[N]`.
1125 * @since C++20
1126 * @relates unique_ptr
1127 */
1128 template<typename _Tp, typename... _Args>
1129 __detail::__invalid_make_unique_t<_Tp>
1130 make_unique_for_overwrite(_Args&&...) = delete;
1131#endif // C++20
1132
1133#endif // C++14 && HOSTED
1134
1135#if __cplusplus > 201703L && __cpp_concepts && _GLIBCXX_HOSTED
1136 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1137 // 2948. unique_ptr does not define operator<< for stream output
1138 /// Stream output operator for unique_ptr
1139 /// @relates unique_ptr
1140 /// @since C++20
1141 template<typename _CharT, typename _Traits, typename _Tp, typename _Dp>
1144 const unique_ptr<_Tp, _Dp>& __p)
1145 requires requires { __os << __p.get(); }
1146 {
1147 __os << __p.get();
1148 return __os;
1149 }
1150#endif // C++20 && HOSTED
1151
1152 /// @} group pointer_abstractions
1153
1154#if __cplusplus >= 201703L
1155 namespace __detail::__variant
1156 {
1157 template<typename> struct _Never_valueless_alt; // see <variant>
1158
1159 // Provide the strong exception-safety guarantee when emplacing a
1160 // unique_ptr into a variant.
1161 template<typename _Tp, typename _Del>
1162 struct _Never_valueless_alt<std::unique_ptr<_Tp, _Del>>
1164 { };
1165 } // namespace __detail::__variant
1166#endif // C++17
1167
1168_GLIBCXX_END_NAMESPACE_VERSION
1169} // namespace
1170
1171#endif /* _UNIQUE_PTR_H */
__detail::__invalid_make_unique_t< _Tp > make_unique_for_overwrite(_Args &&...)=delete
constexpr __detail::__unique_ptr_array_t< _Tp > make_unique_for_overwrite(size_t __num)
Definition: unique_ptr.h:1120
constexpr __detail::__unique_ptr_array_t< _Tp > make_unique(size_t __num)
Definition: unique_ptr.h:1085
constexpr enable_if< __is_swappable< _Dp >::value >::type swap(unique_ptr< _Tp, _Dp > &__x, unique_ptr< _Tp, _Dp > &__y) noexcept
Definition: unique_ptr.h:814
__detail::__invalid_make_unique_t< _Tp > make_unique(_Args &&...)=delete
constexpr __detail::__unique_ptr_t< _Tp > make_unique_for_overwrite()
Definition: unique_ptr.h:1107
constexpr __detail::__unique_ptr_t< _Tp > make_unique(_Args &&... __args)
Definition: unique_ptr.h:1070
typename remove_extent< _Tp >::type remove_extent_t
Alias template for remove_extent.
Definition: type_traits:1971
auto declval() noexcept -> decltype(__declval< _Tp >(0))
Definition: type_traits:2327
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition: move.h:104
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
Definition: any:429
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
Definition: move.h:77
ISO C++ entities toplevel namespace is std.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
Definition: bitset:1685
Template class basic_ostream.
Definition: ostream:61
Primary class template hash.
integral_constant
Definition: type_traits:63
Define a member typedef type only if a boolean constant is true.
Definition: type_traits:107
is_void
Definition: type_traits:299
is_array
Definition: type_traits:478
is_pointer
Definition: type_traits:500
is_lvalue_reference
Definition: type_traits:505
is_same
Definition: type_traits:1369
is_copy_constructible
Definition: type_traits:1048
is_move_constructible
Definition: type_traits:1070
is_assignable
Definition: type_traits:1126
common_type
Definition: type_traits:2186
A simple smart pointer providing strict ownership semantics.
Definition: auto_ptr.h:94
One of the comparison functors.
Definition: stl_function.h:404
constexpr void operator()(_Tp *__ptr) const
Calls delete __ptr
Definition: unique_ptr.h:94
constexpr default_delete() noexcept=default
Default constructor.
constexpr enable_if< is_convertible< _Up(*)[], _Tp(*)[]>::value >::type operator()(_Up *__ptr) const
Calls delete[] __ptr
Definition: unique_ptr.h:137
constexpr default_delete() noexcept=default
Default constructor.
A move-only smart pointer that manages unique ownership of a resource.
Definition: unique_ptr.h:279
constexpr pointer operator->() const noexcept
Return the stored pointer.
Definition: unique_ptr.h:461
constexpr unique_ptr & operator=(nullptr_t) noexcept
Reset the unique_ptr to empty, invoking the deleter if necessary.
Definition: unique_ptr.h:441
constexpr unique_ptr(pointer __p) noexcept
Definition: unique_ptr.h:318
constexpr unique_ptr() noexcept
Default constructor, creates a unique_ptr that owns nothing.
Definition: unique_ptr.h:305
constexpr unique_ptr(pointer __p, const deleter_type &__d) noexcept
Definition: unique_ptr.h:332
unique_ptr(unique_ptr &&)=default
Move constructor.
unique_ptr & operator=(unique_ptr &&)=default
Move assignment operator.
constexpr void reset(pointer __p=pointer()) noexcept
Replace the stored pointer.
Definition: unique_ptr.h:506
constexpr 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.
Definition: unique_ptr.h:431
~unique_ptr() noexcept
Destructor, invokes the deleter if the stored pointer is not null.
Definition: unique_ptr.h:399
constexpr unique_ptr(unique_ptr< _Up, _Ep > &&__u) noexcept
Converting constructor from another type.
Definition: unique_ptr.h:381
constexpr deleter_type & get_deleter() noexcept
Return a reference to the stored deleter.
Definition: unique_ptr.h:476
constexpr add_lvalue_reference< element_type >::type operator*() const noexcept(noexcept(*std::declval< pointer >()))
Dereference the stored pointer.
Definition: unique_ptr.h:452
constexpr void swap(unique_ptr &__u) noexcept
Exchange the pointer and deleter with another object.
Definition: unique_ptr.h:516
constexpr pointer get() const noexcept
Return the stored pointer.
Definition: unique_ptr.h:470
constexpr unique_ptr(pointer __p, __enable_if_t<!is_lvalue_reference< _Del >::value, _Del && > __d) noexcept
Definition: unique_ptr.h:345
constexpr pointer release() noexcept
Release ownership of any stored pointer.
Definition: unique_ptr.h:495
constexpr unique_ptr(nullptr_t) noexcept
Creates a unique_ptr that owns nothing.
Definition: unique_ptr.h:360
constexpr const deleter_type & get_deleter() const noexcept
Return a reference to the stored deleter.
Definition: unique_ptr.h:482
constexpr deleter_type & get_deleter() noexcept
Return a reference to the stored deleter.
Definition: unique_ptr.h:738
constexpr pointer release() noexcept
Release ownership of any stored pointer.
Definition: unique_ptr.h:757
constexpr unique_ptr(nullptr_t) noexcept
Creates a unique_ptr that owns nothing.
Definition: unique_ptr.h:653
constexpr void swap(unique_ptr &__u) noexcept
Exchange the pointer and deleter with another object.
Definition: unique_ptr.h:790
constexpr const deleter_type & get_deleter() const noexcept
Return a reference to the stored deleter.
Definition: unique_ptr.h:744
constexpr unique_ptr & operator=(nullptr_t) noexcept
Reset the unique_ptr to empty, invoking the deleter if necessary.
Definition: unique_ptr.h:712
constexpr unique_ptr() noexcept
Default constructor, creates a unique_ptr that owns nothing.
Definition: unique_ptr.h:586
constexpr void reset(_Up __p) noexcept
Replace the stored pointer.
Definition: unique_ptr.h:780
constexpr pointer get() const noexcept
Return the stored pointer.
Definition: unique_ptr.h:732
constexpr unique_ptr(_Up __p, __enable_if_t<!is_lvalue_reference< _Del >::value, _Del && > __d) noexcept
Definition: unique_ptr.h:635
constexpr 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.
Definition: unique_ptr.h:702
constexpr unique_ptr(_Up __p) noexcept
Definition: unique_ptr.h:604
unique_ptr & operator=(unique_ptr &&)=default
Move assignment operator.
unique_ptr(unique_ptr &&)=default
Move constructor.
constexpr unique_ptr(_Up __p, const deleter_type &__d) noexcept
Definition: unique_ptr.h:620
~unique_ptr()
Destructor, invokes the deleter if the stored pointer is not null.
Definition: unique_ptr.h:671
constexpr std::add_lvalue_reference< element_type >::type operator[](size_t __i) const
Access an element of owned array.
Definition: unique_ptr.h:723