YSTest: memory.hpp 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

memory.hpp
浏览该文件的文档.
1 /*
2 © 2011-2016 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
30 #ifndef YB_INC_ystdex_memory_hpp_
31 #define YB_INC_ystdex_memory_hpp_ 1
32
33 #include "addressof.hpp" // for "addressof.hpp", <memory>, and_,
34 // is_copy_constructible, is_class_type, cond_t, vdefer, detected_t,
35 // conditional, ystdex::constfn_addressof, indirect_element_t,
36 // remove_reference_t, detected_or_t, is_void, remove_pointer_t,
37 // is_pointer, enable_if_t, is_array, extent, remove_extent_t;
38 #include "type_op.hpp" // for is_class_type, is_nonconst_object;
39 #include <iterator> // for std::iterator_traits;
40 #include "cassert.h" // for yconstraint;
41 #include "deref_op.hpp" // for is_undereferenceable;
42 #include <new> // for placement ::operator new from standard library;
43 #include "operators.hpp" // for totally_ordered, equality_comparable;
44
45 #if YB_IMPL_MSCPP >= 1800
46
51 # ifndef __cpp_lib_make_unique
52 # define __cpp_lib_make_unique 201304
53 # endif
54 #endif
55
56 namespace ystdex
57 {
58
60
61 namespace details
62 {
63
64 template<typename _type>
65 using is_copy_constructible_class
66 = and_<is_copy_constructible<_type>, is_class_type<_type>>;
67
68
70 template<class _tAlloc, typename _type>
71 using rebind_t = typename _tAlloc::template rebind<_type>::other;
72
73 // XXX: Details member across headers?
75 template<typename _type>
76 using check_allocator = and_<cond_t<has_mem_value_type<_type>,
77 is_detected<rebind_t, _type, vdefer<details::mem_value_type_t, _type>>>,
78 is_copy_constructible_class<_type>>;
79
81 template<typename _type>
82 using nested_allocator_t = typename _type::allocator_type;
83
84
86
87 template<typename _type>
88 struct pack_obj_impl
89 {
90 template<typename... _tParams>
91 static _type
92 pack(_tParams&&... args)
93 {
94 return _type(yforward(args)...);
95 }
96 };
97
98 template<typename _type, class _tDeleter>
99 struct pack_obj_impl<std::unique_ptr<_type, _tDeleter>>
100 {
101 template<typename... _tParams>
102 static std::unique_ptr<_type>
103 pack(_tParams&&... args)
104 {
105 return std::unique_ptr<_type>(yforward(args)...);
106 }
107 };
108
109 template<typename _type>
110 struct pack_obj_impl<std::shared_ptr<_type>>
111 {
112 template<typename... _tParams>
113 static std::shared_ptr<_type>
114 pack(_tParams&&... args)
115 {
116 return std::shared_ptr<_type>(yforward(args)...);
117 }
118 };
120
121 } // namespace details;
122
123
129 template<typename _type>
130 struct is_allocatable : is_nonconst_object<_type>
131 {};
132
133
138 template<typename _type>
139 struct has_nested_allocator
140 : details::check_allocator<detected_t<details::nested_allocator_t, _type>>
141 {};
142
143
148 template<typename _type, class _tDefault = std::allocator<_type>>
149 struct nested_allocator
150 : conditional<has_nested_allocator<_type>::value,
151 detected_t<details::nested_allocator_t, _type>, _tDefault>
152 {};
154
155
162 template<typename _type, typename... _tParams>
163 inline void
164 construct_in(_type& obj, _tParams&&... args)
165 {
166 ::new(static_cast<void*>(static_cast<_type*>(
167 ystdex::constfn_addressof(obj)))) _type(yforward(args)...);
168 }
169
171
172
174
187 template<typename _tIter, typename... _tParams>
188 void
189 construct(_tIter i, _tParams&&... args)
190 {
191 using value_type = typename std::iterator_traits<_tIter>::value_type;
192
193 yconstraint(!is_undereferenceable(i));
194 ystdex::construct_in<value_type>(*i, yforward(args)...);
195 }
196
201 template<typename _tIter, typename... _tParams>
202 void
203 construct_range(_tIter first, _tIter last, _tParams&&... args)
204 {
205 for(; first != last; ++first)
206 ystdex::construct(first, yforward(args)...);
207 }
209
216 template<typename _type>
217 inline void
218 destruct_in(_type& obj)
219 {
220 obj.~_type();
221 }
222
223
231 template<typename _tIter>
232 void
233 destruct(_tIter i)
234 {
235 using value_type = typename std::iterator_traits<_tIter>::value_type;
236
237 yconstraint(!is_undereferenceable(i));
238 ystdex::destruct_in<value_type>(*i);
239 }
240
246 template<typename _tIter>
247 void
248 destruct_range(_tIter first, _tIter last)
249 {
250 for(; first != last; ++first)
251 ystdex::destruct(first);
252 }
254
255
271 template<typename _tFwd, typename... _tParams>
272 void
273 uninitialized_construct(_tFwd first, _tFwd last, _tParams&&... args)
274 {
275 auto i = first;
276
277 try
278 {
279 for(; i != last; ++i)
280 ystdex::construct(i, yforward(args)...);
281 }
282 catch(...)
283 {
284 // NOTE: The order is unspecified.
285 ystdex::destruct_range(first, i);
286 throw;
287 }
288 }
289
296 template<typename _tFwd, typename _tSize, typename... _tParams>
297 void
298 uninitialized_construct_n(_tFwd first, _tSize n, _tParams&&... args)
299 {
300 auto i = first;
301
302 try
303 {
304 // NOTE: This form is by specification (WG21 N4431) of
305 // 'std::unitialized_fill' literally.
306 for(; n--; ++i)
307 ystdex::construct(i, yforward(args)...);
308 }
309 catch(...)
310 {
311 // NOTE: The order is unspecified.
312 ystdex::destruct_range(first, i);
313 throw;
314 }
315 }
317
318
319
329 template<typename _type>
330 struct free_delete
331 {
332 yconstfn free_delete() ynothrow = default;
333 template<typename _type2,
334 yimpl(typename = enable_if_convertible_t<_type2*, _type*>)>
335 free_delete(const free_delete<_type2>&) ynothrow
336 {}
337
339 void
340 operator()(_type* p) const ynothrowv
341 {
342 p->~_type();
343 std::free(p);
344 }
345 };
346
347 template<typename _type>
348 struct free_delete<_type[]>
349 {
351
352 static_assert(is_trivially_destructible<_type>(), "Invalid type found");
353
354 yconstfn free_delete() ynothrow = default;
355 template<typename _type2,
356 yimpl(typename = enable_if_convertible_t<_type2(*)[], _type(*)[]>)>
357 free_delete(const free_delete<_type2[]>&) ynothrow
358 {}
359
360 template<typename _type2,
361 yimpl(typename = enable_if_convertible_t<_type2(*)[], _type(*)[]>)>
362 void
363 operator()(_type2* p) const ynothrowv
364 {
365 std::free(p);
366 }
368 };
370
371
378 template<typename>
379 struct temporary_buffer_delete;
380
381 template<typename _type>
382 struct temporary_buffer_delete<_type[]>
383 {
384 yconstfn temporary_buffer_delete() ynothrow = default;
385
386 void
387 operator()(_type* p) const ynothrowv
388 {
389 std::return_temporary_buffer(p);
390 }
391 };
393
394
400 template<typename _type>
401 class temporary_buffer
402 {
403 public:
404 using array_type = _type[];
405 using element_type = _type;
406 using deleter = temporary_buffer_delete<array_type>;
407 using pointer = std::unique_ptr<_type, deleter>;
408
409 private:
410 std::pair<pointer, size_t> buf;
411
412 public:
414 temporary_buffer(size_t n)
415 : buf([n]{
416 // NOTE: See http://wg21.cmeerw.net/lwg/issue2072.
417 const auto pr(std::get_temporary_buffer<_type>(ptrdiff_t(n)));
418
419 if(pr.first)
420 return std::pair<pointer, size_t>(pointer(pr.first),
421 size_t(pr.second));
422 throw std::bad_cast();
423 }())
424 {}
425 temporary_buffer(temporary_buffer&&) = default;
426 temporary_buffer&
427 operator=(temporary_buffer&&) = default;
428
430 yconstfn const pointer&
431 get() const ynothrow
432 {
433 return buf.first;
434 }
435
436 pointer&
437 get_pointer_ref() ynothrow
438 {
439 return buf.first;
440 }
441
442 size_t
443 size() const ynothrow
444 {
445 return buf.second;
446 }
447 };
449
450
455 template<class _tAlloc>
456 class allocator_delete
457 {
458 private:
459 using traits = std::allocator_traits<_tAlloc>;
460
461 public:
462 using pointer = typename traits::pointer;
463 using size_type = typename traits::size_type;
464
465 private:
466 _tAlloc& alloc_ref;
467 size_type size;
468
469 public:
470 allocator_delete(_tAlloc& alloc, size_type s)
471 : alloc_ref(alloc), size(s)
472 {}
473
474 void
475 operator()(pointer p) const ynothrowv
476 {
477 traits::deallocate(alloc_ref, p, size);
478 }
479 };
480
481
483
484 template<typename _type, class _tAlloc
486 = std::allocator<indirect_element_t<_type>>>
487 auto
488 clone_monomorphic(const _type& p, _tAlloc&& a = _tAlloc())
489 -> decltype(std::addressof(*p))
490 {
491 using traits = std::allocator_traits<_tAlloc>;
492 using value_type = typename traits::value_type;
493
494 auto p_allocated(traits::allocate(a, sizeof(value_type)));
495 const auto p_storage(std::addressof(*p_allocated));
496
497 traits::construct(a, p_storage, *p);
498 return p_storage;
499 }
500
505 template<class _type>
506 auto
507 clone_polymorphic(const _type& p) -> decltype(std::addressof(*p))
508 {
509 static_assert(is_polymorphic<indirect_element_t<decltype(p)>>(),
510 "Non-polymorphic class type found.");
511
512 return p->clone();
513 }
515
516
522 template<class _tDeleter>
524 using deleter_member_pointer_t
525 = typename remove_reference_t<_tDeleter>::pointer;
526
528 template<typename _type, class _tDeleter>
529 using unique_ptr_pointer
530 = detected_or_t<_type*, deleter_member_pointer_t, _tDeleter>;
531
537 template<typename _tPointer, typename _tDefault = void>
538 using defer_element = cond_t<is_void<remove_pointer_t<_tPointer>>, _tDefault,
539 vdefer<indirect_element_t, _tPointer>>;
541
542
548 template<typename _type>
549 yconstfn _type*
550 get_raw(_type* const& p) ynothrow
551 {
552 return p;
553 }
555 template<typename _type, typename _fDeleter>
556 yconstfn auto
557 get_raw(const std::unique_ptr<_type, _fDeleter>& p) ynothrow
558 -> decltype(p.get())
559 {
560 return p.get();
561 }
562 template<typename _type>
563 yconstfn _type*
564 get_raw(const std::shared_ptr<_type>& p) ynothrow
565 {
566 return p.get();
567 }
568 template<typename _type>
569 yconstfn _type*
570 get_raw(const std::weak_ptr<_type>& p) ynothrow
571 {
572 return p.lock().get();
573 }
575
582 template<typename _type>
583 inline bool
584 reset(std::unique_ptr<_type>& p) ynothrow
585 {
586 if(p.get())
587 {
588 p.reset();
589 return true;
590 }
591 return {};
592 }
593 template<typename _type>
594 inline bool
595 reset(std::shared_ptr<_type>& p) ynothrow
596 {
597 if(p.get())
598 {
599 p.reset();
600 return true;
601 }
602 return {};
603 }
605
606
615 template<typename _type, typename _pSrc>
616 yconstfn std::unique_ptr<_type>
617 unique_raw(_pSrc* p) ynothrow
618 {
619 return std::unique_ptr<_type>(p);
620 }
621 template<typename _type>
622 yconstfn std::unique_ptr<_type>
623 unique_raw(_type* p) ynothrow
624 {
625 return std::unique_ptr<_type>(p);
626 }
627 template<typename _type, typename _tDeleter, typename _pSrc>
628 yconstfn std::unique_ptr<_type, _tDeleter>
629 unique_raw(_pSrc* p, _tDeleter&& d) ynothrow
630 {
631 return std::unique_ptr<_type, _tDeleter>(p, yforward(d));
632 }
633 template<typename _type, typename _tDeleter>
634 yconstfn std::unique_ptr<_type, _tDeleter>
635 unique_raw(_type* p, _tDeleter&& d) ynothrow
636 {
637 return std::unique_ptr<_type, _tDeleter>(p, yforward(d));
638 }
643 template<typename _type>
644 yconstfn std::unique_ptr<_type>
645 unique_raw(nullptr_t) ynothrow
646 {
647 return std::unique_ptr<_type>();
648 }
650
651
660
662 template<typename _type, typename... _tParams>
663 yconstfn std::shared_ptr<_type>
664 share_raw(_type* p, _tParams&&... args)
665 {
666 return std::shared_ptr<_type>(p, yforward(args)...);
667 }
672 template<typename _type, typename _pSrc, typename... _tParams>
673 yconstfn std::shared_ptr<_type>
674 share_raw(_pSrc&& p, _tParams&&... args)
675 {
676 static_assert(is_pointer<remove_reference_t<_pSrc>>(),
677 "Invalid type found.");
678
679 return std::shared_ptr<_type>(p, yforward(args)...);
680 }
682
686 template<typename _type>
687 yconstfn std::shared_ptr<_type>
688 share_raw(nullptr_t) ynothrow
689 {
690 return std::shared_ptr<_type>();
691 }
697 template<typename _type, class... _tParams>
698 yconstfn yimpl(enable_if_t)<sizeof...(_tParams) != 0, std::shared_ptr<_type>>
699 share_raw(nullptr_t, _tParams&&... args) ynothrow
700 {
701 return std::shared_ptr<_type>(nullptr, yforward(args)...);
702 }
704
705
706 inline namespace cpp2014
707 {
708
709 #if __cpp_lib_make_unique >= 201304 || __cplusplus > 201103L
710 using std::make_unique;
712 #else
713
727 template<typename _type, typename... _tParams>
728 yconstfn yimpl(enable_if_t<!is_array<_type>::value, std::unique_ptr<_type>>)
729 make_unique(_tParams&&... args)
730 {
731 return std::unique_ptr<_type>(new _type(yforward(args)...));
732 }
733 template<typename _type, typename... _tParams>
734 yconstfn yimpl(enable_if_t<is_array<_type>::value && extent<_type>::value == 0,
735 std::unique_ptr<_type>>)
736 make_unique(size_t size)
737 {
738 return std::unique_ptr<_type>(new remove_extent_t<_type>[size]());
739 }
740 template<typename _type, typename... _tParams>
741 yimpl(enable_if_t<extent<_type>::value != 0>)
742 make_unique(_tParams&&...) = delete;
744 #endif
745
746 } // inline namespace cpp2014;
747
754 template<typename _type, typename... _tParams>
755 yconstfn yimpl(enable_if_t<!is_array<_type>::value, std::unique_ptr<_type>>)
756 make_unique_default_init()
757 {
758 return std::unique_ptr<_type>(new _type);
759 }
760 template<typename _type, typename... _tParams>
761 yconstfn yimpl(enable_if_t<is_array<_type>::value && extent<_type>::value == 0,
762 std::unique_ptr<_type>>)
763 make_unique_default_init(size_t size)
764 {
765 return std::unique_ptr<_type>(new remove_extent_t<_type>[size]);
766 }
767 template<typename _type, typename... _tParams>
768 yimpl(enable_if_t<extent<_type>::value != 0>)
769 make_unique_default_init(_tParams&&...) = delete;
771
778 template<typename _type, typename _tValue>
779 yconstfn std::unique_ptr<_type>
780 make_unique(std::initializer_list<_tValue> il)
781 {
782 return ystdex::make_unique<_type>(il);
783 }
784
790 template<typename _type, typename _tDeleter, typename... _tParams>
791 yconstfn yimpl(enable_if_t<!is_array<_type>::value, std::unique_ptr<_type>>)
792 make_unique_with(_tDeleter&& d)
793 {
794 return std::unique_ptr<_type, _tDeleter>(new _type, yforward(d));
795 }
796 template<typename _type, typename _tDeleter, typename... _tParams>
797 yconstfn yimpl(enable_if_t<is_array<_type>::value && extent<_type>::value == 0,
798 std::unique_ptr<_type>>)
799 make_unique_with(_tDeleter&& d, size_t size)
800 {
801 return std::unique_ptr<_type, _tDeleter>(new remove_extent_t<_type>[size],
802 yforward(d));
803 }
804 template<typename _type, typename _tDeleter, typename... _tParams>
805 yimpl(enable_if_t<extent<_type>::value != 0>)
806 make_unique_with(_tDeleter&&, _tParams&&...) = delete;
808
809
817 template<typename _type, typename _tValue>
818 yconstfn std::shared_ptr<_type>
819 make_shared(std::initializer_list<_tValue> il)
820 {
821 return std::make_shared<_type>(il);
822 }
823
824
829 template<typename _tAlloc>
830 std::unique_ptr<_tAlloc, allocator_delete<_tAlloc>>
831 make_allocator_guard(_tAlloc& alloc,
832 typename std::allocator_traits<_tAlloc>::size_type n = 1)
833 {
834 using del_t = allocator_delete<_tAlloc>;
835
836 return std::unique_ptr<_tAlloc, del_t>(alloc.allocate(n), del_t(alloc, n));
837 }
838
839
845 template<typename _tDst, typename _type>
846 std::unique_ptr<_tDst>
847 static_pointer_cast(std::unique_ptr<_type> p) ynothrow
848 {
849 return std::unique_ptr<_tDst>(static_cast<_tDst*>(p.release()));
850 }
851 template<typename _tDst, typename _type, typename _tDeleter>
852 std::unique_ptr<_tDst, _tDeleter>
853 static_pointer_cast(std::unique_ptr<_type, _tDeleter> p) ynothrow
854 {
855 return std::unique_ptr<_tDst, _tDeleter>(static_cast<_tDst*>(p.release()),
856 std::move(p.get_deleter()));
857 }
858
859 template<typename _tDst, typename _type>
860 std::unique_ptr<_tDst>
861 dynamic_pointer_cast(std::unique_ptr<_type>& p) ynothrow
862 {
863 if(auto p_res = dynamic_cast<_tDst*>(p.get()))
864 {
865 p.release();
866 return std::unique_ptr<_tDst>(p_res);
867 }
868 return std::unique_ptr<_tDst>();
869 }
870 template<typename _tDst, typename _type>
871 std::unique_ptr<_tDst>
872 dynamic_pointer_cast(std::unique_ptr<_type>&& p) ynothrow
873 {
874 return ystdex::dynamic_pointer_cast<_tDst, _type>(p);
875 }
876 template<typename _tDst, typename _type, typename _tDeleter>
877 std::unique_ptr<_tDst, _tDeleter>
878 dynamic_pointer_cast(std::unique_ptr<_type, _tDeleter>& p) ynothrow
879 {
880 if(auto p_res = dynamic_cast<_tDst*>(p.get()))
881 {
882 p.release();
883 return std::unique_ptr<_tDst, _tDeleter>(p_res);
884 }
885 return std::unique_ptr<_tDst, _tDeleter>(nullptr);
886 }
887 template<typename _tDst, typename _type, typename _tDeleter>
888 std::unique_ptr<_tDst, _tDeleter>
889 dynamic_pointer_cast(std::unique_ptr<_type, _tDeleter>&& p) ynothrow
890 {
891 return ystdex::dynamic_pointer_cast<_tDst, _type, _tDeleter>(p);
892 }
893
894 template<typename _tDst, typename _type>
895 std::unique_ptr<_tDst>
896 const_pointer_cast(std::unique_ptr<_type> p) ynothrow
897 {
898 return std::unique_ptr<_tDst>(const_cast<_tDst*>(p.release()));
899 }
900 template<typename _tDst, typename _type, typename _tDeleter>
901 std::unique_ptr<_tDst, _tDeleter>
902 const_pointer_cast(std::unique_ptr<_type, _tDeleter> p) ynothrow
903 {
904 return std::unique_ptr<_tDst, _tDeleter>(const_cast<_tDst*>(p.release()),
905 std::move(p.get_deleter()));
906 }
908
909
911
912
916 template<typename _type>
917 class observer_ptr : private totally_ordered<observer_ptr<_type>>,
918 private equality_comparable<observer_ptr<_type>, nullptr_t>
919 {
920 public:
921 using element_type = _type;
922 using pointer = yimpl(add_pointer_t<_type>);
923 using reference = yimpl(add_lvalue_reference_t<_type>);
924
925 private:
926 _type* ptr{};
927
928 public:
930
931 yconstfn
932 observer_ptr() ynothrow yimpl(= default);
933 yconstfn
934 observer_ptr(nullptr_t) ynothrow
935 : ptr()
936 {}
938 explicit yconstfn
939 observer_ptr(pointer p) ynothrow
940 : ptr(p)
941 {}
942 template<typename _tOther>
943 yconstfn
944 observer_ptr(observer_ptr<_tOther> other) ynothrow
945 : ptr(other.get())
946 {}
947
949 yconstfn reference
950 operator*() const ynothrowv
951 {
952 return yconstraint(get() != nullptr), *ptr;
953 }
954
955 yconstfn pointer
956 operator->() const ynothrow
957 {
958 return ptr;
959 }
960
962 friend yconstfn bool
963 operator==(observer_ptr p, nullptr_t) ynothrow
964 {
965 return !p.ptr;
966 }
967
968 explicit yconstfn
969 operator bool() const ynothrow
970 {
971 return ptr;
972 }
973
974 explicit yconstfn
975 operator pointer() const ynothrow
976 {
977 return ptr;
978 }
979
980 yconstfn pointer
981 get() const ynothrow
982 {
983 return ptr;
984 }
985
986 yconstfn_relaxed pointer
987 release() ynothrow
988 {
989 const auto res(ptr);
990
991 reset();
992 return res;
993 }
994
995 yconstfn_relaxed void
996 reset(pointer p = {}) ynothrow
997 {
998 ptr = p;
999 }
1000
1001 yconstfn_relaxed void
1002 swap(observer_ptr& other) ynothrow
1003 {
1004 std::swap(ptr, other.ptr);
1005 }
1006 };
1007
1009
1010
1012 template<typename _type1, typename _type2>
1013 yconstfn bool
1014 operator==(observer_ptr<_type1> p1, observer_ptr<_type2> p2) ynothrowv
1015 {
1016 return p1.get() == p2.get();
1017 }
1018
1019 template<typename _type1, typename _type2>
1020 yconstfn bool
1021 operator!=(observer_ptr<_type1> p1, observer_ptr<_type2> p2) ynothrowv
1022 {
1023 return !(p1 == p2);
1024 }
1025
1026 template<typename _type1, typename _type2>
1027 yconstfn bool
1028 operator<(observer_ptr<_type1> p1, observer_ptr<_type2> p2) ynothrowv
1029 {
1030 return std::less<common_type_t<_type1, _type2>>(p1.get(), p2.get());
1031 }
1033
1034 template<typename _type>
1035 inline void
1036 swap(observer_ptr<_type>& p1, observer_ptr<_type>& p2) ynothrow
1037 {
1038 p1.swap(p2);
1039 }
1040 template<typename _type>
1041 inline observer_ptr<_type>
1042 make_observer(_type* p) ynothrow
1043 {
1044 return observer_ptr<_type>(p);
1045 }
1047
1048
1049
1051
1052
1059 template<typename _type, typename... _tParams>
1060 auto
1061 pack_object(_tParams&&... args)
1062 -> decltype(yimpl(details::pack_obj_impl<_type>::pack(yforward(args)...)))
1063 {
1064 return details::pack_obj_impl<_type>::pack(yforward(args)...);
1065 }
1066
1067
1069 template<typename _type, typename _tPack = std::unique_ptr<_type>>
1070 struct object_pack
1071 {
1072 public:
1073 using value_type = _type;
1074 using pack_type = _tPack;
1075
1076 private:
1077 pack_type pack;
1078
1079 public:
1081 template<typename... _tParams>
1082 object_pack(_tParams&&... args)
1083 : pack(pack_object<_tPack>(yforward(args)...))
1084 {}
1085
1086 operator pack_type&() ynothrow
1087 {
1088 return pack;
1089 }
1090 operator const pack_type&() const ynothrow
1091 {
1092 return pack;
1093 }
1094 };
1096
1097 } // namespace ystdex;
1098
1099
1100 namespace std
1101 {
1102
1109 template<typename>
1110 struct hash;
1111
1112 template<typename _type>
1113 struct hash<ystdex::observer_ptr<_type>>
1114 {
1115 size_t
1116 operator()(const ystdex::observer_ptr<_type>& p) const yimpl(ynothrow)
1117 {
1118 return hash<_type*>(p.get());
1119 }
1120 };
1122
1123 } // namespace std;
1124
1125 #endif
1126
ystdex::clone_monomorphic
auto clone_monomorphic(const _type &p, _tAlloc &&a=_tAlloc()) -> decltype(std::addressof(*p))
使用分配器复制指定指针指向的对象。
Definition: memory.hpp:488
ystdex::temporary_buffer::get_pointer_ref
pointer & get_pointer_ref()
Definition: memory.hpp:437
platform::p
while p p
Definition: YCLib/FileSystem.h:225
ystdex::operator==
bool operator==(nullptr_t lhs, const _type &rhs)
Definition: ydef.h:869
ystdex::object_pack::value_type
_type value_type
Definition: memory.hpp:1073
ystdex::observer_ptr::release
pointer release()
Definition: memory.hpp:987
ystdex::observer_ptr::pointer
add_pointer_t< _type > pointer
Definition: memory.hpp:922
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:740
ystdex::temporary_buffer::temporary_buffer
temporary_buffer(size_t n)
Definition: memory.hpp:414
ystdex::enable_if_convertible_t
enable_if_t< is_convertible< _tFrom, _tTo >::value, _type > enable_if_convertible_t
Definition: type_traits.hpp:993
yconstraint
#define yconstraint(_expr)
约束：接口语义。
Definition: cassert.h:82
ystdex::cpp2014::remove_extent_t
typename remove_extent< _type >::type remove_extent_t
Definition: type_traits.hpp:321
ystdex::is_detected
typename details::detector< nonesuch, void, _gOp, _tParams... >::value_t is_detected
Definition: type_traits.hpp:667
ystdex::swap
void swap(container_adaptor< _tSeqCon > &x, container_adaptor< _tSeqCon > &y)
Definition: container.hpp:179
cassert.h
ISO C 断言/调试跟踪扩展。
YSLib::Drawing::p1
The boundary is out of the const Graphics const Rect const Point & p1
Definition: YDraw.h:161
ystdex::operator!=
bool operator!=(nullptr_t lhs, const _type &rhs)
Definition: ydef.h:882
deref_op.hpp
解引用操作。
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: type_traits.hpp:350
ystdex::temporary_buffer::array_type
_type[] array_type
Definition: memory.hpp:404
ystdex::has_nested_allocator
判断类型具有嵌套的成员 allocator_type 指称一个可复制构造的类类型。
Definition: memory.hpp:139
ystdex::swap
void swap(observer_ptr< _type > &p1, observer_ptr< _type > &p2)
Definition: memory.hpp:1036
ystdex::temporary_buffer_delete
使用显式 std::return_temporary_buffer 的删除器。
Definition: memory.hpp:379
ystdex::is_nonconst_object
判断类型是否为非 const 对象类型。
Definition: type_traits.hpp:765
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:760
ystdex::details::nested_allocator_t
typename _type::allocator_type nested_allocator_t
Definition: memory.hpp:82
platform::size_t
YF_API size_t
Definition: FileIO.h:1262
ystdex::make_unique
std::unique_ptr< _type > make_unique(std::initializer_list< _tValue > il)
使用指定类型的初始化列表构造指定类型的 std::unique_ptr 对象。
Definition: memory.hpp:780
CHRLib::d
_tDst * d
Definition: CharacterProcessing.h:139
ystdex::reset
bool reset(std::unique_ptr< _type > &p)
Definition: memory.hpp:584
ystdex::get_raw
_type * get_raw(_type *const &p)
Definition: memory.hpp:550
ystdex::const_pointer_cast
std::unique_ptr< _tDst > const_pointer_cast(std::unique_ptr< _type > p)
Definition: memory.hpp:896
ystdex::details::rebind_t
typename _tAlloc::template rebind< _type >::other rebind_t
Definition: memory.hpp:71
addressof.hpp
一元操作符 & 和取指针的相关接口。
ystdex::is_allocatable
判断类型是否符合分配器要求的目标类型。
Definition: memory.hpp:130
ystdex::observer_ptr::operator*
reference operator*() const
Definition: memory.hpp:950
ystdex::unique_ptr_pointer
detected_or_t< _type *, deleter_member_pointer_t, _tDeleter > unique_ptr_pointer
取 unique_ptr 包装的指针类型。
Definition: memory.hpp:530
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:256
YSLib::Drawing::p2
The boundary is out of the const Graphics const Rect const Point const Point & p2
Definition: YDraw.h:161
ystdex::construct
void construct(_tIter i, _tParams &&...args)
使用指定参数在迭代器指定的位置构造对象。
Definition: memory.hpp:189
ystdex::object_pack::object_pack
object_pack(_tParams &&...args)
Definition: memory.hpp:1082
ystdex::temporary_buffer_delete< _type[]>::operator()
void operator()(_type *p) const
Definition: memory.hpp:387
ystdex::allocator_delete::pointer
typename traits::pointer pointer
Definition: memory.hpp:462
ystdex::make_allocator_guard
std::unique_ptr< _tAlloc, allocator_delete< _tAlloc > > make_allocator_guard(_tAlloc &alloc, typename std::allocator_traits< _tAlloc >::size_type n=1)
构造分配器守护。
Definition: memory.hpp:831
ystdex::details::pack_obj_impl::pack
static _type pack(_tParams &&...args)
Definition: memory.hpp:92
ystdex::constfn_addressof
enable_if_t<!has_overloaded_addressof< _type >::value, _type * > constfn_addressof(_type &r)
尝试对非重载 operator& 提供 constexpr 的 std::addressof 替代。
Definition: addressof.hpp:78
ystdex::pack_object
auto pack_object(_tParams &&...args) -> decltype(details::pack_obj_impl< _type >::pack(std::forward< decltype(args)>(args)...))
打包对象：通过指定参数构造对象。
Definition: memory.hpp:1061
ystdex::share_raw
std::shared_ptr< _type > share_raw(_type *p, _tParams &&...args)
Definition: memory.hpp:664
ystdex::observer_ptr::reset
void reset(pointer p={})
Definition: memory.hpp:996
ystdex::uninitialized_construct_n
void uninitialized_construct_n(_tFwd first, _tSize n, _tParams &&...args)
Definition: memory.hpp:298
ystdex::construct_in
void construct_in(_type &obj, _tParams &&...args)
原地构造。
Definition: memory.hpp:164
ystdex::free_delete::operator()
void operator()(_type *p) const
Definition: memory.hpp:340
yconstfn_relaxed
#define yconstfn_relaxed
指定编译时没有 C++11 限制和隐式成员 const 的常量函数。
Definition: ydef.h:666
std
Definition: memory.hpp:1100
ystdex::uninitialized_construct
void uninitialized_construct(_tFwd first, _tFwd last, _tParams &&...args)
在迭代器指定的未初始化的范围上构造对象。
Definition: memory.hpp:273
ystdex::details::pack_obj_impl< std::unique_ptr< _type, _tDeleter > >::pack
static std::unique_ptr< _type > pack(_tParams &&...args)
Definition: memory.hpp:103
ystdex::static_pointer_cast
std::unique_ptr< _tDst > static_pointer_cast(std::unique_ptr< _type > p)
智能指针转换。
Definition: memory.hpp:847
ystdex::observer_ptr::ptr
_type * ptr
Definition: memory.hpp:926
ystdex::observer_ptr::observer_ptr
observer_ptr()=default
ystdex::free_delete
使用显式析构函数调用和 std::free 的删除器。
Definition: memory.hpp:330
ystdex::detected_or_t
_t< detected_or< _tDefault, _gOp, _tParams... >> detected_or_t
Definition: type_traits.hpp:678
ystdex::cpp2014::make_unique
enable_if_t<!is_array< _type >::value, std::unique_ptr< _type > > make_unique(_tParams &&...args)
使用 new 和指定参数构造指定类型的 std::unique_ptr 对象。
Definition: memory.hpp:729
ystdex::size
auto size(const _tRange &c) -> decltype(c.size())
类容器访问。
Definition: range.hpp:233
std::hash
ystdex::observer_ptr 散列支持。
Definition: memory.hpp:1110
ystdex::observer_ptr::observer_ptr
observer_ptr(observer_ptr< _tOther > other)
Definition: memory.hpp:944
ystdex::make_unique_default_init
enable_if_t<!is_array< _type >::value, std::unique_ptr< _type > > make_unique_default_init()
Definition: memory.hpp:756
ystdex::destruct_range
void destruct_range(_tIter first, _tIter last)
析构d迭代器范围内的对象序列。
Definition: memory.hpp:248
ystdex::observer_ptr::element_type
_type element_type
Definition: memory.hpp:921
ystdex::deleter_member_pointer_t
typename remove_reference_t< _tDeleter >::pointer deleter_member_pointer_t
取删除器的 pointer 成员类型。
Definition: memory.hpp:525
ystdex::temporary_buffer::element_type
_type element_type
Definition: memory.hpp:405
ystdex
特性测试宏。
Definition: ydef.h:796
ystdex::allocator_delete::size
size_type size
Definition: memory.hpp:467
ystdex::temporary_buffer::operator=
temporary_buffer & operator=(temporary_buffer &&)=default
ystdex::cond_t
conditional_t< _tCond::value, _tThen, _tElse > cond_t
条件判断。
Definition: type_traits.hpp:698
ystdex::indirect_element_t
remove_reference_t< indirect_t< _type >> indirect_element_t
Definition: type_traits.hpp:983
ystdex::object_pack
打包的对象：使用 pack_object 得到的对象包装。
Definition: memory.hpp:1070
ystdex::temporary_buffer::pointer
std::unique_ptr< _type, deleter > pointer
Definition: memory.hpp:407
std::hash< ystdex::observer_ptr< _type > >::operator()
size_t operator()(const ystdex::observer_ptr< _type > &p) const
Definition: memory.hpp:1116
ystdex::is_undereferenceable
bool is_undereferenceable(const _tIter &)
Definition: deref_op.hpp:45
ystdex::nullptr_t
空指针类。
Definition: ydef.h:835
YSLib::i
return i
Definition: YCoreUtilities.h:176
ystdex::allocator_delete::traits
std::allocator_traits< _tAlloc > traits
Definition: memory.hpp:459
ystdex::destruct_in
void destruct_in(_type &obj)
原地析构。
Definition: memory.hpp:218
ystdex::allocator_delete::alloc_ref
_tAlloc & alloc_ref
Definition: memory.hpp:466
ystdex::temporary_buffer
临时缓冲区。
Definition: memory.hpp:401
ystdex::temporary_buffer::size
size_t size() const
Definition: memory.hpp:443
ystdex::construct_range
void construct_range(_tIter first, _tIter last, _tParams &&...args)
使用指定的参数重复构造迭代器范围内的对象序列。
Definition: memory.hpp:203
operators.hpp
重载操作符。
ystdex::allocator_delete::allocator_delete
allocator_delete(_tAlloc &alloc, size_type s)
Definition: memory.hpp:470
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:654
type_op.hpp
C++ 类型操作。
ystdex::allocator_delete::operator()
void operator()(pointer p) const
Definition: memory.hpp:475
ystdex::observer_ptr
观察者指针：无所有权的智能指针。
Definition: memory.hpp:917
ystdex::free_delete::free_delete
free_delete()=default
ystdex::details::pack_obj_impl
Definition: memory.hpp:88
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:167
ystdex::make_unique_with
enable_if_t<!is_array< _type >::value, std::unique_ptr< _type > > make_unique_with(_tDeleter &&d)
Definition: memory.hpp:792
ystdex::details::pack_obj_impl< std::shared_ptr< _type > >::pack
static std::shared_ptr< _type > pack(_tParams &&...args)
Definition: memory.hpp:114
CHRLib::CharSet::other
Definition: Encoding.h:65
ystdex::make_shared
std::shared_ptr< _type > make_shared(std::initializer_list< _tValue > il)
使用指定类型的初始化列表构造指定类型的 std::shared_ptr 对象。
Definition: memory.hpp:819
ystdex::free_delete< _type[]>::free_delete
free_delete(const free_delete< _type2[]> &)
Definition: memory.hpp:357
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:969
ystdex::destruct
void destruct(_tIter i)
析构迭代器指向的对象。
Definition: memory.hpp:233
ystdex::is_class_type
判断指定类型是否是类类型。
Definition: type_traits.hpp:755
ystdex::free_delete::free_delete
free_delete(const free_delete< _type2 > &)
Definition: memory.hpp:335
ystdex::make_observer
observer_ptr< _type > make_observer(_type *p)
Definition: memory.hpp:1042
ystdex::object_pack::pack_type
_tPack pack_type
Definition: memory.hpp:1074
ystdex::object_pack::pack
pack_type pack
Definition: memory.hpp:1077
ystdex::observer_ptr::observer_ptr
observer_ptr(pointer p)
Definition: memory.hpp:939
ystdex::dep_ops::totally_ordered
details::flat_ops< _type, _type2, _tOpt, less_than_comparable, equality_comparable > totally_ordered
Definition: operators.hpp:367
ystdex::dep_ops::equality_comparable
_t< details::ops_seq< _type, _type2, _tOpt, cond_t< is_same< _type, _type2 >, index_sequence< 7 >, index_sequence< 6, 7, 8 >>>> equality_comparable
Definition: operators.hpp:243
ystdex::free_delete< _type[]>::operator()
void operator()(_type2 *p) const
Definition: memory.hpp:363
CHRLib::args
_tParams && args
Definition: CharacterProcessing.h:538
ystdex::observer_ptr::swap
void swap(observer_ptr &other)
Definition: memory.hpp:1002
ystdex::clone_polymorphic
auto clone_polymorphic(const _type &p) -> decltype(std::addressof(*p))
使用 clone 成员函数复制指定指针指向的多态类类型对象。
Definition: memory.hpp:507
ystdex::allocator_delete::size_type
typename traits::size_type size_type
Definition: memory.hpp:463
ystdex::temporary_buffer::buf
std::pair< pointer, size_t > buf
Definition: memory.hpp:410
ystdex::details::is_copy_constructible_class
and_< is_copy_constructible< _type >, is_class_type< _type >> is_copy_constructible_class
Definition: memory.hpp:66
ystdex::observer_ptr::operator->
pointer operator->() const
Definition: memory.hpp:956
ystdex::and_
逻辑操作元函数。
Definition: type_traits.hpp:394
ystdex::observer_ptr::operator==
friend bool operator==(observer_ptr p, nullptr_t)
Definition: memory.hpp:963
ystdex::unique_raw
std::unique_ptr< _type > unique_raw(_pSrc *p)
Definition: memory.hpp:617
ystdex::defer_element
cond_t< is_void< remove_pointer_t< _tPointer >>, _tDefault, vdefer< indirect_element_t, _tPointer >> defer_element
取指针对应的元素类型。
Definition: memory.hpp:539
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
platform::bool
std::FILE *fp bool
Definition: FileIO.h:1187
ystdex::nested_allocator
取嵌套成员分配器类型，若不存在则使用第二模板参数指定的默认类型。
Definition: memory.hpp:149
ystdex::dynamic_pointer_cast
std::unique_ptr< _tDst > dynamic_pointer_cast(std::unique_ptr< _type > &p)
Definition: memory.hpp:861
ystdex::allocator_delete
释放分配器的删除器。
Definition: memory.hpp:456
platform::n
size_t n
Definition: YCLib/FileSystem.cpp:321
ystdex::observer_ptr::reference
add_lvalue_reference_t< _type > reference
Definition: memory.hpp:923