MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
unique_ptr.hpp
浏览该文件的文档.
1#ifndef MSTL_CORE_MEMORY_UNIQUE_PTR_HPP__
2#define MSTL_CORE_MEMORY_UNIQUE_PTR_HPP__
3
11
16
22
30template <typename T>
32 constexpr default_delete() noexcept = default;
33
38 template <typename U, enable_if_t<is_convertible<U*, T*>::value, int> = 0>
39 MSTL_CONSTEXPR20 default_delete(const default_delete<U>&) noexcept {}
40
45 MSTL_CONSTEXPR20 void operator ()(const T* ptr) const noexcept {
46 delete ptr;
47 }
48
54 template <typename U>
55 MSTL_CONSTEXPR20 default_delete<U> rebind() && noexcept {
56 return default_delete<U>();
57 }
58};
59
64template <typename T>
65struct default_delete<T[]> {
66 constexpr default_delete() noexcept = default;
67
72 template <typename U, enable_if_t<is_convertible<U(*)[], T(*)[]>::value, int> = 0>
73 MSTL_CONSTEXPR20 default_delete(const default_delete<U[]>&) noexcept {}
74
80 template <typename U, enable_if_t<is_convertible<U(*)[], T(*)[]>::value, int> = 0>
81 MSTL_CONSTEXPR20 void operator ()(U* ptr) const noexcept {
82 delete [] ptr;
83 }
84
90 template <typename U>
91 MSTL_CONSTEXPR20 default_delete<U[]> rebind() && noexcept {
92 return default_delete<U[]>();
93 }
94};
95
98
107template <typename T, typename Deleter>
108class __unique_ptr_impl {
109private:
110 template <typename U, typename E, typename = void>
111 struct inner_ptr {
112 using type = U*;
113 };
114 template <typename U, typename E>
115 struct inner_ptr<U, E, void_t<typename remove_reference_t<E>::pointer>> {
116 using type = typename remove_reference<E>::type::pointer;
117 };
118
119public:
120 using DeleterConstraint = enable_if<is_default_constructible<Deleter>::value>;
121 using pointer = typename inner_ptr<T, Deleter>::type;
122
123private:
124 _MSTL tuple<pointer, Deleter> tup{};
125
127 "deleter type of unique_ptr must be a function object type or an lvalue reference type");
128
129public:
130 __unique_ptr_impl() = default;
131 MSTL_CONSTEXPR20 __unique_ptr_impl(pointer ptr) : tup() { get_ptr() = ptr; }
132
133 template <typename Del>
134 MSTL_CONSTEXPR20 __unique_ptr_impl(pointer ptr, Del&& del)
135 : tup(ptr, _MSTL forward<Del>(del)) {}
136
137 MSTL_CONSTEXPR20 __unique_ptr_impl(__unique_ptr_impl&& ptr) noexcept
138 : tup(_MSTL move(ptr.tup)) { ptr.get_ptr() = nullptr; }
139
140 MSTL_CONSTEXPR20 __unique_ptr_impl& operator =(__unique_ptr_impl&& x) noexcept {
141 reset(x.release());
142 get_deleter() = _MSTL forward<Deleter>(x.get_deleter());
143 return *this;
144 }
145
146 MSTL_CONSTEXPR20 pointer& get_ptr() noexcept { return _MSTL get<0>(tup); }
147 MSTL_CONSTEXPR20 pointer get_ptr() const noexcept { return _MSTL get<0>(tup); }
148 MSTL_CONSTEXPR20 Deleter& get_deleter() noexcept { return _MSTL get<1>(tup); }
149 MSTL_CONSTEXPR20 const Deleter& get_deleter() const noexcept { return _MSTL get<1>(tup); }
150
151 MSTL_CONSTEXPR20 void reset(pointer ptr) noexcept {
152 const pointer old = get_ptr();
153 get_ptr() = ptr;
154 if (old) {
155 get_deleter()(old);
156 }
157 }
158
159 MSTL_CONSTEXPR20 pointer release() noexcept {
160 pointer p = get_ptr();
161 get_ptr() = nullptr;
162 return p;
163 }
164
165 MSTL_CONSTEXPR20 void swap(__unique_ptr_impl& x) noexcept {
166 _MSTL swap(get_ptr(), x.get_ptr());
167 _MSTL swap(get_deleter(), x.get_deleter());
168 }
169};
170
181template <typename T, typename Deleter,
182 bool MoveConstructible = is_move_constructible<Deleter>::value,
183 bool MoveAssignable = is_move_assignable<Deleter>::value>
184struct __unique_ptr_data : __unique_ptr_impl<T, Deleter> {
185 using base_type = __unique_ptr_impl<T, Deleter>;
186 using pointer = typename base_type::pointer;
187
188 __unique_ptr_data() = default;
189 MSTL_CONSTEXPR20 __unique_ptr_data(pointer ptr) : base_type(ptr) {}
190
191 template <typename Del>
192 MSTL_CONSTEXPR20 __unique_ptr_data(pointer ptr, Del&& del) : base_type(ptr, _MSTL forward<Del>(del)) {}
193
194 __unique_ptr_data(__unique_ptr_data&&) = default;
195 __unique_ptr_data& operator =(__unique_ptr_data&&) = default;
196};
197
198// 删除器可移动构造但不可移动赋值
199template <typename T, typename Deleter>
200struct __unique_ptr_data<T, Deleter, true, false> : __unique_ptr_impl<T, Deleter> {
201 using base_type = __unique_ptr_impl<T, Deleter>;
202 using pointer = typename base_type::pointer;
203
204 __unique_ptr_data() = default;
205 MSTL_CONSTEXPR20 __unique_ptr_data(pointer ptr) : base_type(ptr) {}
206
207 template <typename Del>
208 MSTL_CONSTEXPR20 __unique_ptr_data(pointer ptr, Del&& del) : base_type(ptr, _MSTL forward<Del>(del)) {}
209
210 __unique_ptr_data(__unique_ptr_data&&) = default;
211 __unique_ptr_data& operator =(__unique_ptr_data&&) = delete;
212};
213
214// 删除器可移动赋值但不可移动构造
215template <typename T, typename Deleter>
216struct __unique_ptr_data<T, Deleter, false, true> : __unique_ptr_impl<T, Deleter> {
217 using base_type = __unique_ptr_impl<T, Deleter>;
218 using pointer = typename base_type::pointer;
219
220 __unique_ptr_data() = default;
221 MSTL_CONSTEXPR20 __unique_ptr_data(pointer ptr) : base_type(ptr) {}
222
223 template <typename Del>
224 MSTL_CONSTEXPR20 __unique_ptr_data(pointer ptr, Del&& del) : base_type(ptr, _MSTL forward<Del>(del)) {}
225
226 __unique_ptr_data(__unique_ptr_data&&) = delete;
227 __unique_ptr_data& operator =(__unique_ptr_data&&) = default;
228};
229
230// 删除器既不可移动构造也不可移动赋值
231template <typename T, typename Deleter>
232struct __unique_ptr_data<T, Deleter, false, false> : __unique_ptr_impl<T, Deleter> {
233 using base_type = __unique_ptr_impl<T, Deleter>;
234 using pointer = typename base_type::pointer;
235
236 __unique_ptr_data() = default;
237 MSTL_CONSTEXPR20 __unique_ptr_data(pointer ptr) : base_type(ptr) {}
238
239 template <typename Del>
240 MSTL_CONSTEXPR20 __unique_ptr_data(pointer ptr, Del&& del) : base_type(ptr, _MSTL forward<Del>(del)) {}
241
242 __unique_ptr_data(__unique_ptr_data&&) = delete;
243 __unique_ptr_data& operator =(__unique_ptr_data&&) = delete;
244};
245
248
249
258template <typename T, typename Deleter = default_delete<T>>
260private:
261 template <typename U>
262 using DeleterConstraint =
263 typename _INNER __unique_ptr_impl<T, U>::DeleterConstraint::type;
264
265 _INNER __unique_ptr_data<T, Deleter> data_{};
266
267public:
268 using pointer = typename _INNER __unique_ptr_impl<T, Deleter>::pointer;
269 using element_type = T;
270 using deleter_type = Deleter;
271
272private:
273 template <typename U, typename E>
274 using safe_conversion = conjunction<
277
278public:
283 template <typename Del = Deleter, typename = DeleterConstraint<Del>>
284 constexpr unique_ptr(nullptr_t = nullptr) noexcept {}
285
291 template <typename Del = Deleter, typename = DeleterConstraint<Del>>
292 MSTL_CONSTEXPR20 unique_ptr(pointer p) noexcept : data_(p) {}
293
300 template <typename Del = deleter_type,
302 MSTL_CONSTEXPR20 unique_ptr(pointer ptr, const deleter_type& del)
303 noexcept : data_(ptr, del) {}
304
311 template <typename Del = deleter_type,
313 MSTL_CONSTEXPR20 unique_ptr(pointer ptr, Del&& del)
314 noexcept : data_(ptr, _MSTL move(del)) {}
315
319 template <typename Del = deleter_type, typename DelMoveRef = remove_reference_t<Del>>
320 MSTL_CONSTEXPR20 unique_ptr(pointer, enable_if_t<is_lvalue_reference<Del>::value, DelMoveRef&&>) = delete;
321
322 MSTL_CONSTEXPR20 unique_ptr(unique_ptr&&) = default;
323
330 template <typename U, typename E, enable_if_t<conjunction<safe_conversion<U, E>,
331 conditional_t<is_reference<Deleter>::value, is_same<E, Deleter>, is_convertible<E, Deleter>>>::value, int> = 0>
332 MSTL_CONSTEXPR20 unique_ptr(unique_ptr<U, E>&& x) noexcept
333 : data_(x.release(), _MSTL forward<E>(x.get_deleter())) {}
334
338 ~unique_ptr() noexcept {
339 static_assert(is_invocable<deleter_type&, pointer>::value, "deleter of unique_ptr must be invocable with a pointer");
340 auto& ptr = data_.get_ptr();
341 if (ptr != nullptr)
342 get_deleter()(_MSTL move(ptr));
343 ptr = pointer();
344 }
345
347
355 template <typename U, typename E, enable_if_t<conjunction<
356 safe_conversion<U, E>, is_assignable<deleter_type&, E&&>>::value, int> = 0>
357 MSTL_CONSTEXPR20 unique_ptr& operator =(unique_ptr<U, E>&& x) noexcept {
358 reset(x.release());
359 get_deleter() = _MSTL forward<E>(x.get_deleter());
360 return *this;
361 }
362
367 MSTL_CONSTEXPR20 unique_ptr& operator =(nullptr_t) noexcept {
368 reset();
369 return *this;
370 }
371
377 noexcept(noexcept(*_MSTL declval<pointer>())) {
378 return *get();
379 }
380
385 MSTL_CONSTEXPR20 pointer operator ->() const noexcept {
386 return get();
387 }
388
389 MSTL_CONSTEXPR20 pointer get() const noexcept { return data_.get_ptr(); }
390 MSTL_CONSTEXPR20 deleter_type& get_deleter() noexcept { return data_.get_deleter(); }
391 MSTL_CONSTEXPR20 const deleter_type& get_deleter() const noexcept { return data_.get_deleter(); }
392
397 MSTL_CONSTEXPR20 explicit operator bool() const noexcept {
398 return get() == pointer() ? false : true;
399 }
400
404 MSTL_CONSTEXPR20 pointer release() noexcept {
405 return data_.release();
406 }
407
411 MSTL_CONSTEXPR20 void reset(pointer ptr = pointer()) noexcept {
413 "deleter of unique_ptr must be invocable with a pointer");
414 data_.reset(_MSTL move(ptr));
415 }
416
421 MSTL_CONSTEXPR20 void swap(unique_ptr& x) noexcept {
422 static_assert(is_swappable<Deleter>::value, "deleter must be swappable.");
423 data_.swap(x.data_);
424 }
425
426 unique_ptr(const unique_ptr&) = delete;
427 unique_ptr& operator =(const unique_ptr&) = delete;
428};
429
435template <typename T, typename Deleter>
436class unique_ptr<T[], Deleter> {
437 template <typename U>
438 using DeleterConstraint =
439 typename _INNER __unique_ptr_impl<T, U>::DeleterConstraint::type;
440
441 _INNER __unique_ptr_data<T, Deleter> data_;
442
443public:
444 using pointer = typename _INNER __unique_ptr_impl<T, Deleter>::pointer;
445 using element_type = T;
446 using deleter_type = Deleter;
447
448private:
449 template <typename U, typename E, typename UP = unique_ptr<U, E>,
450 typename UP_pointer = typename UP::pointer,
451 typename UP_element_type = typename UP::element_type>
454
455 template <typename U>
459
460public:
467 template <typename U, typename Del = Deleter, typename = DeleterConstraint<Del>,
468 enable_if_t<safe_conversion_raw<U>::value, int> = 0>
469 MSTL_CONSTEXPR20 explicit unique_ptr(U ptr) noexcept : data_(ptr) {}
470
478 template <typename U, typename Del = deleter_type,
480 MSTL_CONSTEXPR20 unique_ptr(U ptr, const deleter_type& del) noexcept
481 : data_(ptr, del) {}
482
490 template <typename U, typename Del = deleter_type,
492 MSTL_CONSTEXPR20 unique_ptr(U ptr, enable_if_t<!is_lvalue_reference<Del>::value, Del&&> del) noexcept
493 : data_(_MSTL move(ptr), _MSTL move(del)) {}
494
498 template <typename U, typename Del = deleter_type, typename DelMoveRef = remove_reference_t<Del>,
499 enable_if_t<safe_conversion_raw<U>::value, int> = 0>
501
502 unique_ptr(unique_ptr&&) = default;
503
508 template <typename Del = Deleter, typename = DeleterConstraint<Del>>
509 constexpr unique_ptr(nullptr_t = nullptr) noexcept : data_() {}
510
517 template <typename U, typename E, enable_if_t<conjunction<safe_conversion<U, E>,
518 conditional_t<is_reference<Deleter>::value, is_same<E, Deleter>, is_convertible<E, Deleter>>>::value, int> = 0>
519 MSTL_CONSTEXPR20 unique_ptr(unique_ptr<U, E>&& x) noexcept
520 : data_(x.release(), _MSTL forward<E>(x.get_deleter())) {}
521
525 MSTL_CONSTEXPR20 ~unique_ptr() {
526 auto& ptr = data_.get_ptr();
527 if (ptr != nullptr) {
528 get_deleter()(ptr);
529 }
530 ptr = pointer();
531 }
532
534
542 template <typename U, typename E, enable_if_t<conjunction<
543 safe_conversion<U, E>, is_assignable<deleter_type&, E&&>, int>::value> = 0>
544 MSTL_CONSTEXPR20 unique_ptr& operator =(unique_ptr<U, E>&& x) noexcept {
545 unique_ptr::reset(x.release());
546 get_deleter() = _MSTL forward<E>(x.get_deleter());
547 return *this;
548 }
549
554 MSTL_CONSTEXPR20 unique_ptr& operator =(nullptr_t) noexcept {
555 reset();
556 return *this;
557 }
558
564 MSTL_CONSTEXPR20 add_lvalue_reference_t<element_type> operator [](size_t idx) const {
565 MSTL_DEBUG_VERIFY(get() != pointer(), "_MSTL add_lvalue_reference_t<element_type> failed");
566 return get()[idx];
567 }
568
569 MSTL_CONSTEXPR20 pointer get() const noexcept { return data_.get_ptr(); }
570 MSTL_CONSTEXPR20 deleter_type& get_deleter() noexcept { return data_.get_deleter(); }
571 MSTL_CONSTEXPR20 const deleter_type& get_deleter() const noexcept { return data_.get_deleter(); }
572
577 MSTL_CONSTEXPR20 explicit operator bool() const noexcept {
578 return get() == pointer() ? false : true;
579 }
580
584 MSTL_CONSTEXPR20 pointer release() noexcept {
585 return data_.release();
586 }
587
593 template <typename U, enable_if_t<
598 >::value, int> = 0>
599 MSTL_CONSTEXPR20 void reset(U ptr) noexcept { data_.reset(_MSTL move(ptr)); }
600
604 MSTL_CONSTEXPR20 void reset(nullptr_t = nullptr) noexcept {
606 }
607
612 MSTL_CONSTEXPR20 void swap(unique_ptr& x) noexcept {
613 static_assert(is_swappable<Deleter>::value, "deleter must be swappable");
614 data_.swap(x.data_);
615 }
616
617 unique_ptr(const unique_ptr&) = delete;
618 unique_ptr& operator =(const unique_ptr&) = delete;
619};
620
628template <typename T, typename Deleter,
631 lhs.swap(rhs);
632}
633
644template <typename T, typename D, typename U, typename E>
645MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator ==(
646 const unique_ptr<T, D>& lhs, const unique_ptr<U, E>& rhs) {
647 return lhs.get() == rhs.get();
648}
649
657template <typename T, typename D>
658MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator ==(
659 const unique_ptr<T, D>& lhs, nullptr_t) {
660 return !lhs;
661}
662
670template <typename T, typename D>
671MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator ==(
672 nullptr_t, const unique_ptr<T, D>& rhs) {
673 return !rhs;
674}
675
686template <typename T, typename D, typename U, typename E>
687MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator !=(
688 const unique_ptr<T, D>& lhs, const unique_ptr<U, E>& rhs) {
689 return lhs.get() != rhs.get();
690}
691
699template <typename T, typename D>
700MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator !=(
701 const unique_ptr<T, D>& lhs, nullptr_t) {
702 return static_cast<bool>(lhs);
703}
704
712template <typename T, typename D>
713MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator !=(
714 nullptr_t, const unique_ptr<T, D>& rhs) {
715 return static_cast<bool>(rhs);
716}
717
728template <typename T, typename D, typename U, typename E>
729MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator <(
730 const unique_ptr<T, D>& lhs, const unique_ptr<U, E>& rhs) {
731 using common_t = common_type_t<
734 return _MSTL less<common_t>()(lhs.get(), rhs.get());
735}
736
744template <typename T, typename D>
745MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator <(
746 const unique_ptr<T, D>& lhs, nullptr_t) {
747 return _MSTL less<typename unique_ptr<T, D>::pointer>()(lhs.get(), nullptr);
748}
749
757template <typename T, typename D>
758MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator <(
759 nullptr_t, const unique_ptr<T, D>& rhs) {
760 return _MSTL less<typename unique_ptr<T, D>::pointer>()(nullptr, rhs.get());
761}
762
773template <typename T, typename D, typename U, typename E>
774MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator >(
775 const unique_ptr<T, D>& lhs, const unique_ptr<U, E>& rhs) {
776 return rhs.get() < lhs.get();
777}
778
786template <typename T, typename D>
787MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator >(
788 const unique_ptr<T, D>& lhs, nullptr_t) {
789 return _MSTL less<typename unique_ptr<T, D>::pointer>()(nullptr, lhs.get());
790}
791
799template <typename T, typename D>
800MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator >(
801 nullptr_t, const unique_ptr<T, D>& rhs) {
802 return _MSTL less<typename unique_ptr<T, D>::pointer>()(rhs.get(), nullptr);
803}
804
815template <typename T, typename D, typename U, typename E>
816MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator <=(
817 const unique_ptr<T, D>& lhs, const unique_ptr<U, E>& rhs) {
818 return !(lhs > rhs);
819}
820
828template <typename T, typename D>
829MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator <=(
830 const unique_ptr<T, D>& lhs, nullptr_t) {
831 return !(lhs > nullptr);
832}
833
841template <typename T, typename D>
842MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator <=(
843 nullptr_t, const unique_ptr<T, D>& rhs) {
844 return !(nullptr > rhs);
845}
846
857template <typename T, typename D, typename U, typename E>
858MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator >=(
859 const unique_ptr<T, D>& lhs, const unique_ptr<U, E>& rhs) {
860 return !(lhs < rhs);
861}
862
870template <typename T, typename D>
871MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator >=(
872 const unique_ptr<T, D>& lhs, nullptr_t) {
873 return !(lhs < nullptr);
874}
875
883template <typename T, typename D>
884MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator >=(
885 nullptr_t, const unique_ptr<T, D>& rhs) {
886 return !(nullptr < rhs);
887}
888
889
897template <typename T, typename U>
899
907template <typename T, typename U>
909
917template <typename T, typename U>
919
927template <typename T, typename U>
929
930
938template <typename T, typename U>
940 return unique_ptr<T>(static_cast<T*>(ptr.release()), ptr.get_deleter());
941}
942
950template <typename T, typename U>
952 return unique_ptr<T>(const_cast<T*>(ptr.release()), ptr.get_deleter());
953}
954
962template <typename T, typename U>
964 return unique_ptr<T>(reinterpret_cast<T*>(ptr.release()), ptr.get_deleter());
965}
966
974template <typename T, typename U>
976 T* tmp = dynamic_cast<T*>(ptr.release());
977 if (tmp != nullptr) {
978 return unique_ptr<T>(tmp, _MSTL move(ptr.get_deleter()).template rebind<T>());
979 }
980 return nullptr;
981}
982
983
989template <typename T, typename Deleter>
990struct hash<unique_ptr<T, Deleter>> {
996 MSTL_CONSTEXPR20 size_t operator ()(const unique_ptr<T, Deleter>& ptr) const
997 noexcept(noexcept(hash<T>()(ptr.get()))) {
998 return hash<T>()(ptr.get());
999 }
1000};
1001
1002
1010template <typename T, typename... Args, enable_if_t<!is_array<T>::value, int> = 0>
1011MSTL_CONSTEXPR20 unique_ptr<T> make_unique(Args&&... args) {
1012 return unique_ptr<T>(new T(_MSTL forward<Args>(args)...));
1013}
1014
1021template <typename T, enable_if_t<is_unbounded_array<T>::value, int> = 0>
1022MSTL_CONSTEXPR20 unique_ptr<T> make_unique(const size_t len) {
1023 return unique_ptr<T>(new remove_extent_t<T>[len]());
1024}
1025
1031template <typename T, typename... Args, enable_if_t<is_bounded_array<T>::value, int> = 0>
1032unique_ptr<T> make_unique(Args&&...) = delete;
1033 // UniquePointer
1035
1037#endif // MSTL_CORE_MEMORY_UNIQUE_PTR_HPP__
unique_ptr(unique_ptr &&)=default
移动构造函数
MSTL_CONSTEXPR20 const deleter_type & get_deleter() const noexcept
获取const删除器引用
MSTL_CONSTEXPR20 pointer get() const noexcept
获取原始指针
MSTL_CONSTEXPR20 void reset(nullptr_t=nullptr) noexcept
重置为空指针
MSTL_CONSTEXPR20 void reset(U ptr) noexcept
重置管理的指针
unique_ptr(U, enable_if_t< is_lvalue_reference< Del >::value, DelMoveRef && >)=delete
禁止从右值引用删除器构造
MSTL_CONSTEXPR20 unique_ptr(U ptr) noexcept
从指针构造
MSTL_CONSTEXPR20 unique_ptr(unique_ptr< U, E > &&x) noexcept
从其他unique_ptr转换构造
MSTL_CONSTEXPR20 pointer release() noexcept
释放所有权
constexpr unique_ptr(nullptr_t=nullptr) noexcept
空指针构造
Deleter deleter_type
删除器类型
MSTL_CONSTEXPR20 ~unique_ptr()
析构函数
MSTL_CONSTEXPR20 unique_ptr(U ptr, const deleter_type &del) noexcept
从指针和复制删除器构造
MSTL_CONSTEXPR20 deleter_type & get_deleter() noexcept
获取删除器引用
typename _INNER __unique_ptr_impl< T, Deleter >::pointer pointer
指针类型
MSTL_CONSTEXPR20 void swap(unique_ptr &x) noexcept
交换两个unique_ptr
unique_ptr(const unique_ptr &)=delete
禁止复制构造
MSTL_CONSTEXPR20 unique_ptr(U ptr, enable_if_t<!is_lvalue_reference< Del >::value, Del && > del) noexcept
从指针和移动删除器构造
独占智能指针
~unique_ptr() noexcept
析构函数
unique_ptr(const unique_ptr &)=delete
禁止复制构造
constexpr unique_ptr(nullptr_t=nullptr) noexcept
空指针构造
MSTL_CONSTEXPR20 unique_ptr(unique_ptr< U, E > &&x) noexcept
从其他unique_ptr转换构造
MSTL_CONSTEXPR20 pointer release() noexcept
释放所有权
MSTL_CONSTEXPR20 const deleter_type & get_deleter() const noexcept
获取const删除器引用
MSTL_CONSTEXPR20 deleter_type & get_deleter() noexcept
获取删除器引用
default_delete< env_value > deleter_type
MSTL_CONSTEXPR20 unique_ptr(pointer ptr, const deleter_type &del) noexcept
从指针和复制删除器复制构造
MSTL_CONSTEXPR20 pointer operator->() const noexcept
成员访问运算符
MSTL_CONSTEXPR20 pointer get() const noexcept
获取原始指针
MSTL_CONSTEXPR20 unique_ptr(pointer, enable_if_t< is_lvalue_reference< Del >::value, DelMoveRef && >)=delete
禁止从右值引用删除器构造
MSTL_CONSTEXPR20 void swap(unique_ptr &x) noexcept
交换两个unique_ptr
typename _INNER __unique_ptr_impl< env_value, default_delete< env_value > >::pointer pointer
MSTL_CONSTEXPR20 add_lvalue_reference_t< element_type > operator*() const noexcept(noexcept(*_MSTL declval< pointer >()))
解引用运算符
MSTL_CONSTEXPR20 void reset(pointer ptr=pointer()) noexcept
重置管理的指针
MSTL_CONSTEXPR20 unique_ptr(unique_ptr &&)=default
移动构造函数
MSTL_CONSTEXPR20 unique_ptr(pointer ptr, Del &&del) noexcept
从指针和移动删除器移动构造
MSTL_CONSTEXPR20 unique_ptr(pointer p) noexcept
从指针构造
unique_ptr & operator=(unique_ptr &&)=default
移动赋值运算符
MSTL仿函数
typename add_reference< T >::lvalue add_lvalue_reference_t
add_lvalue_reference的便捷别名
MSTL_NODISCARD constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
MSTL_ALWAYS_INLINE enable_if_t< is_void_v< T >, future_result_t< T > > get(future< T > &f)
通用future结果获取函数
decltype(nullptr) nullptr_t
空指针类型
add_rvalue_reference_t< T > declval() noexcept
获取类型的右值引用,仅用于非求值上下文
@ release
释放操作,确保前面的读写不会被重排到后面
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_INNER__
结束inner命名空间
#define _INNER
inner命名空间前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
#define MSTL_BEGIN_INNER__
开始inner命名空间
typename remove_reference< T >::type remove_reference_t
remove_reference的便捷别名
typename remove_extent< T >::type remove_extent_t
remove_extent的便捷别名
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result)
移动范围元素
void swap()=delete
删除无参数的swap重载
typename common_type< Types... >::type common_type_t
common_type的便捷别名
void void_t
将任意类型映射为void
typename enable_if< Test, T >::type enable_if_t
enable_if的便捷别名
MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator!=(const unique_ptr< T, D > &lhs, const unique_ptr< U, E > &rhs)
不等比较运算符
MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator>=(const unique_ptr< T, D > &lhs, const unique_ptr< U, E > &rhs)
大于等于比较运算符
unique_ptr< T > reinterpret_pointer_cast(const unique_ptr< U > &ptr)=delete
禁止的reinterpret_pointer_cast
MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator==(const unique_ptr< T, D > &lhs, const unique_ptr< U, E > &rhs)
相等比较运算符
unique_ptr< T > const_pointer_cast(const unique_ptr< U > &ptr)=delete
禁止的const_pointer_cast
MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator<=(const unique_ptr< T, D > &lhs, const unique_ptr< U, E > &rhs)
小于等于比较运算符
unique_ptr< T > static_pointer_cast(const unique_ptr< U > &ptr)=delete
禁止的static_pointer_cast
MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator>(const unique_ptr< T, D > &lhs, const unique_ptr< U, E > &rhs)
大于比较运算符
MSTL_CONSTEXPR20 unique_ptr< T > make_unique(Args &&... args)
创建unique_ptr
unique_ptr< T > dynamic_pointer_cast(const unique_ptr< U > &ptr)=delete
禁止的dynamic_pointer_cast
MSTL_NODISCARD MSTL_CONSTEXPR20 bool operator<(const unique_ptr< T, D > &lhs, const unique_ptr< U, E > &rhs)
小于比较运算符
MSTL统一调用接口
类型集合的逻辑与操作
MSTL_CONSTEXPR20 default_delete< U[]> rebind() &&noexcept
重新绑定到其他数组类型的删除器
constexpr default_delete() noexcept=default
默认构造函数
MSTL_CONSTEXPR20 default_delete< U > rebind() &&noexcept
重新绑定到其他类型的删除器
MSTL_CONSTEXPR20 void operator()(const T *ptr) const noexcept
删除操作符
constexpr default_delete() noexcept=default
默认构造函数
哈希函数的主模板
判断类型是否可以使用指定类型的值进行赋值
判断类型From是否可以隐式转换为类型To
判断类型是否可复制构造
判断类型是否可调用
判断类型是否可移动构造
判断类型是否为指针类型
判断两个类型是否相同
小于比较仿函数
逻辑非包装器
MSTL元组实现