YSTest: any.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

any.h
浏览该文件的文档.
1 /*
2 © 2011-2020 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
31 #ifndef YB_INC_ystdex_any_h_
32 #define YB_INC_ystdex_any_h_ 1
33
34 #include "typeinfo.h" // for internal "typeinfo.h", type_info, exclude_self_t,
35 // ystdex::type_id, well_formed_t, is_convertible, enable_if_t,
36 // is_nothrow_move_constructible, and_, is_decayed, bool_, noncopyable,
37 // nonmovable, or_, is_copy_constructible, remove_reference_t, cond_t, is_same,
38 // is_class, std::bad_cast, nor_, std::declval, yconstraint, YAssert, decay_t;
39 #include "utility.hpp" // for internal "utility.hpp", boxed_value,
40 // std::addressof, std::unique_ptr, standard_layout_storage, aligned_storage_t,
41 // is_aligned_storable, ystdex::pvoid, default_init_t, default_init, vseq::_a,
42 // is_instance_of, cond_or_t;
43 #include "memory.hpp" // for ystdex::clone_monomorphic_ptr, std::allocator,
44 // allocator_delete, exclude_self_params_t, is_byte_allocator, alloc_value_t,
45 // rebind_alloc_t, allocator_traits, ystdex::allocate_unique, in_place_type_t,
46 // std::allocator_arg_t, in_place_type;
47 #include "exception.h" // for throw_invalid_construction,
48 // throw_allocator_mismatch_error;
49 #include "ref.hpp" // for is_reference_wrapper, unwrap_reference_t;
50 #include <initializer_list> // for std::initializer_list;
51
52 namespace ystdex
53 {
54
67 namespace any_ops
68 {
69
71 template<typename>
72 struct with_handler_t
73 {};
74
75
81 class YB_API YB_ATTR_novtable holder
82 {
83 public:
85
86 holder() = default;
87 holder(const holder&) = default;
89 virtual
90 ~holder();
92
94 YB_ATTR_nodiscard YB_ATTR_returns_nonnull YB_PURE virtual void*
95 get() const = 0;
96
98 YB_ATTR_nodiscard YB_PURE virtual const type_info&
99 type() const ynothrow = 0;
100 };
101
107 YB_ATTR_nodiscard YB_PURE inline bool
108 hold_same(const holder& x, const holder& y)
109 {
110 return x.get() == y.get();
111 }
112
113
119 template<typename _type>
120 class value_holder : protected boxed_value<_type>, public holder
121 {
122 static_assert(is_object<_type>(), "Non-object type found.");
123 static_assert(!is_cv<_type>(), "Cv-qualified type found.");
124
125 public:
127 using value_type = _type;
128
130
131 value_holder() = default;
132 template<typename _tParam,
133 yimpl(typename = exclude_self_t<value_holder, _tParam>)>
134 value_holder(_tParam&& arg)
135 ynoexcept(is_nothrow_constructible<_type, _tParam>())
136 : boxed_value<_type>(yforward(arg))
137 {}
138 using boxed_value<_type>::boxed_value;
140
142 value_holder(const value_holder&) = default;
143 value_holder(value_holder&&) = default;
144
145 value_holder&
146 operator=(const value_holder&) = default;
147 value_holder&
148 operator=(value_holder&&) = default;
150
152 YB_ATTR_nodiscard void*
153 get() const override
154 {
155 return std::addressof(this->value);
156 }
157
159 YB_ATTR_nodiscard YB_PURE const type_info&
160 type() const ynothrow override
161 {
162 return ystdex::type_id<_type>();
163 }
164 };
165
166
176 template<typename _type, class _tPointer = std::unique_ptr<_type>>
177 class pointer_holder : public holder
178 {
180 static_assert(is_object<_type>(), "Invalid type found.");
181
182 public:
184 using value_type = _type;
185 using holder_pointer = _tPointer;
186 using pointer = typename holder_pointer::pointer;
187
188 protected:
189 holder_pointer p_held;
190
191 public:
196 pointer_holder(pointer value)
197 : p_held((yconstraint(bool(value)), value))
198 {}
200
201 pointer_holder(const pointer_holder& h)
202 : pointer_holder(ystdex::clone_monomorphic_ptr(h.p_held))
203 {}
204 pointer_holder(pointer_holder&&) = default;
206
207 pointer_holder&
208 operator=(const pointer_holder&) = default;
209 pointer_holder&
210 operator=(pointer_holder&&) = default;
211
213 YB_ATTR_nodiscard YB_ATTR_returns_nonnull void*
214 get() const override
215 {
216 return p_held.get();
217 }
218
220 YB_ATTR_nodiscard YB_PURE const type_info&
221 type() const ynothrow override
222 {
223 return p_held ? ystdex::type_id<_type>() : ystdex::type_id<void>();
224 }
225 };
226
227
237 using op_code = std::uint32_t;
238
252 enum base_op : op_code
253 {
258 no_op,
266 get_type,
275 get_ptr,
285 clone,
292 destroy,
301 get_holder_type,
310 get_holder_ptr,
324 get_allocator_type,
333 get_allocator_ptr,
344 clone_with_allocator,
358 transfer_with_allocator,
360
366 end_base_op
367 };
368
369
371
372
376 union any_trivial_local_data
377 {
378 void* obj_ptr;
379 const void* const_obj_ptr;
380 void(*fn_ptr)();
381 void* any_trivial_local_data::*mem_ptr;
382 void(any_trivial_local_data::*mem_fn_ptr)();
383 };
384
385
390 union any_local_data
391 {
393 using allocated_t = std::unique_ptr<yimpl(int),
394 allocator_delete<yimpl(std::allocator<int>)>>;
395
396 any_trivial_local_data trivial;
398 aligned_storage_t<sizeof(allocated_t), yalignof(allocated_t)> allocated;
399 };
401
402
404 using any_storage = standard_layout_storage<aligned_storage_t<
405 sizeof(any_local_data), yalignof(any_local_data)>>;
410 using any_manager = void(*)(any_storage&, any_storage&, op_code);
411
416 template<class _tHandler, typename... _tParams>
417 auto
418 construct(any_storage& storage, _tParams&&... args) -> enable_if_t<
419 is_convertible<well_formed_t<decltype(_tHandler::manage),
420 decltype(_tHandler::init(storage, yforward(args)...))>, any_manager>::value,
421 any_manager>
422 {
423 _tHandler::init(storage, yforward(args)...);
424 return _tHandler::manage;
425 }
426
433 template<class _tHandler, typename... _tParams>
434 using is_handler_constructible_t = is_constructible<any_ops::any_manager,
435 decltype(any_ops::construct<_tHandler>(
436 std::declval<any_ops::any_storage&>(), std::declval<_tParams>()...))>;
437
438
445 template<typename _type>
446 using is_in_place_storable = and_<is_aligned_storable<any_storage, _type>>;
447
448
453 yconstexpr const struct use_holder_t{} use_holder{};
454
461 template<class _tHolder>
462 using check_holder_t = and_<is_decayed<_tHolder>, is_class<_tHolder>,
463 is_base_of<holder, _tHolder>, is_convertible<_tHolder&, holder&>>;
464
465
467 namespace details
468 {
469
470 // TODO: Extract as %std::unique_ptr instance?
471 template<typename _tValue>
472 class memory_thunk : private noncopyable, private nonmovable
473 {
474 public:
475 using value_type = _tValue;
476
477 private:
478 std::unique_ptr<value_type> p_val;
479
480 public:
481 template<typename... _tParams,
482 yimpl(typename = exclude_self_params_t<memory_thunk, _tParams...>)>
483 inline
484 memory_thunk(_tParams&&... args)
485 : p_val(make_unique<value_type>(yforward(args)...))
486 {}
487
488 YB_ATTR_nodiscard YB_PURE
489 operator value_type&() const ynothrowv
490 {
491 return get();
492 }
493
494 YB_ATTR_nodiscard YB_PURE value_type&
495 get() const ynothrowv
496 {
497 yassume(bool(p_val));
498 return *p_val;
499 }
500 };
501
502 } // namespace details;
503
521 template<typename _type,
522 bool _bStoredLocally = is_in_place_storable<_type>::value>
523 class value_handler
524 {
526 static_assert(is_decayed<_type>(), "Invalid type found.");
527 static_assert(!_bStoredLocally || is_aligned_storable<any_storage, _type>(),
528 "No enough space to store object locally.");
529
530 public:
532
533 using value_type = _type;
534 using local_storage = bool_<_bStoredLocally>;
536
537 private:
539 using memory_thunk = details::memory_thunk<value_type>;
541 static_assert(or_<local_storage, is_aligned_storable<any_storage,
542 memory_thunk>>(), "Invalid stored target found.");
544 using stored_type = cond_t<local_storage, value_type, memory_thunk>;
545
546 public:
548
549 static void
550 copy(any_storage& d, const any_storage& s)
551 {
552 init_or_throw(is_copy_constructible<value_type>(), d, get_reference(s));
553 }
554
555 static void
556 dispose(any_storage& d) ynothrowv
557 {
558 d.destroy<stored_type>();
559 }
561
563
564 YB_ATTR_nodiscard YB_PURE static value_type*
565 get_pointer(any_storage& s) ynothrow
566 {
567 return std::addressof(get_reference(s));
568 }
569 YB_ATTR_nodiscard YB_PURE static const value_type*
570 get_pointer(const any_storage& s) ynothrow
571 {
572 return std::addressof(get_reference(s));
573 }
574
575 public:
576 YB_ATTR_nodiscard YB_PURE static value_type&
577 get_reference(any_storage& s) ynothrow
578 {
579 return s.access<stored_type>();
580 }
581 YB_ATTR_nodiscard YB_PURE static const value_type&
582 get_reference(const any_storage& s) ynothrow
583 {
584 return s.access<stored_type>();
585 }
587
589 template<typename... _tParams>
590 static
591 enable_if_t<is_constructible<value_type, _tParams...>::value>
592 init(any_storage& d, _tParams&&... args)
593 {
594 d.construct<stored_type>(yforward(args)...);
595 }
596
597 private:
599 template<typename... _tParams>
600 YB_NORETURN static void
601 init_or_throw(false_, _tParams&&...)
602 {
603 throw_invalid_construction();
604 }
606 template<typename... _tParams>
607 static void
608 init_or_throw(true_, any_storage& d, _tParams&&... args)
609 {
610 init(d, yforward(args)...);
611 }
612
613 public:
615 static void
616 manage(any_storage& d, any_storage& s, op_code op)
617 {
618 switch(op)
619 {
620 case get_type:
621 d = &ystdex::type_id<value_type>();
622 break;
623 case get_ptr:
624 d = ystdex::pvoid(get_pointer(s));
625 break;
626 case clone:
627 copy(d, s);
628 break;
629 case destroy:
630 dispose(d);
631 break;
632 case get_holder_type:
633 case get_allocator_type:
634 d = &ystdex::type_id<void>();
635 break;
636 case get_holder_ptr:
637 d = static_cast< holder*>(nullptr);
638 break;
639 case get_allocator_ptr:
640 d = static_cast<void*>(nullptr);
641 }
642 }
643 };
644
645
650 template<typename _type>
651 class ref_handler
652 {
653 public:
654 using value_type = _type;
655 using base = value_handler<value_type*>;
656
658
659 YB_ATTR_nodiscard YB_PURE static value_type*
660 get_pointer(any_storage& s) ynothrow
661 {
662 return base::get_reference(s);
663 }
664 YB_ATTR_nodiscard YB_PURE static const value_type*
665 get_pointer(const any_storage& s) ynothrow
666 {
667 return base::get_reference(s);
668 }
669
670 YB_ATTR_nodiscard YB_PURE static value_type&
671 get_reference(any_storage& s) ynothrowv
672 {
673 yassume(get_pointer(s));
674 return *get_pointer(s);
675 }
676 YB_ATTR_nodiscard YB_PURE static const value_type&
677 get_reference(const any_storage& s) ynothrowv
678 {
679 yassume(get_pointer(s));
680 return *get_pointer(s);
681 }
683
685 template<class _tWrapper,
686 yimpl(typename = enable_if_t<is_reference_wrapper<_tWrapper>::value>)>
687 static auto
688 init(any_storage& d, _tWrapper x)
689 -> decltype(base::init(d, std::addressof(x.get())))
690 {
691 base::init(d, std::addressof(x.get()));
692 }
693
695 static void
696 manage(any_storage& d, any_storage& s, op_code op)
697 {
698 switch(op)
699 {
700 case get_type:
701 d = &ystdex::type_id<value_type>();
702 break;
703 case get_ptr:
704 d = ystdex::pvoid(get_pointer(s));
705 break;
706 default:
707 base::manage(d, s, op);
708 }
709 }
710 };
711
712
720 template<typename _tHolder>
721 class holder_handler : private value_handler<_tHolder>
722 {
723 static_assert(check_holder_t<_tHolder>(), "Invalid holder type found.");
724
725 public:
727 using holder_type = _tHolder;
728 using base = value_handler<holder_type>;
729
731 YB_ATTR_nodiscard YB_PURE static holder_type*
732 get_holder_pointer(any_storage& s) ynothrow
733 {
734 return base::get_pointer(s);
735 }
736
737 private:
739 static void
740 init(false_, any_storage& d, std::unique_ptr<holder_type> p)
741 {
742 d.construct<holder_type*>(p.release());
743 }
745 static void
746 init(true_, any_storage& d, std::unique_ptr<holder_type> p)
747 {
748 d.construct<holder_type>(std::move(*p));
749 }
750
751 public:
753 static auto
754 init(any_storage& d, std::unique_ptr<holder_type> p) -> decltype(
755 init(typename base::local_storage(), d, std::move(p)), void())
756 {
757 init(typename base::local_storage(), d, std::move(p));
758 }
760 using base::init;
761
763 static void
764 manage(any_storage& d, any_storage& s, op_code op)
765 {
766 switch(op)
767 {
768 case get_type:
769 d = &get_holder_pointer(s)->type();
770 break;
771 case get_ptr:
772 d = ystdex::pvoid(get_holder_pointer(s)->get());
773 break;
774 case get_holder_type:
775 d = &ystdex::type_id<holder_type>();
776 break;
777 case get_holder_ptr:
778 d = static_cast< holder*>(get_holder_pointer(s));
779 break;
780 default:
781 base::manage(d, s, op);
782 }
783 }
784 };
785
786
792 template<class _tByteAlloc, typename _tValue>
793 class allocator_value_handler
794 {
795 static_assert(and_<is_byte_allocator<_tByteAlloc>>(),
796 "Invalid base allocator type found.");
797 static_assert(is_decayed<_tValue>(), "Invalid value type found.");
798
799 public:
800 using value_type = _tValue;
801
802 private:
803 using ator_type = rebind_alloc_t<_tByteAlloc, _tValue>;
804 using ator_traits = allocator_traits<ator_type>;
805 using deleter_type = allocator_delete<ator_type>;
806 // NOTE: Since the allocator used here is usually stateful (as opposite to
807 // usual cases with explicitly typed allocators like allocator-aware
808 // container classes), missing the empty base class optimization in
809 // %deleter_type is usually less effective here.
810 // XXX: This does not support over-sized allocator which makes %ator_owner
811 // not fit in %any_storage yet.
812 // XXX: The base is needed to avoid Clang++ warning: [-Wdeprecated].
814
815 struct ator_del final : deleter_type, noncopyable, nonmovable
816 {
817 value_type& ref;
818
819 ator_del(value_type& val, const ator_type& a) ynothrow
820 : deleter_type(a), ref(val)
821 {}
822 ~ator_del()
823 {
824 (*this)(std::addressof(ref));
825 }
826 };
827 #if false
828 // XXX: This is potentially efficient, but not enabled curretly to make the
829 // real (profiled) performance better. See $2019-04
830 // @ %Documentation::Workflow.
831 struct ator_inc final : noncopyable, nonmovable
832 {
833 value_type& ref;
834
835 ator_inc(value_type& val, const ator_type&) ynothrow
836 : ref(val)
837 {}
838 ~ator_inc()
839 {
840 deleter_type(ystdex::as_const(ref).get_allocator())(
841 std::addressof(ref));
842 }
843 };
844 using ator_owner = cond_t<has_get_allocator<value_type>, ator_inc,
845 ator_del>;
846 #else
847 using ator_owner = ator_del;
848 #endif
849
850 using rebound_ator_type = rebind_alloc_t<ator_type, byte>;
852 static_assert(is_in_place_storable<ator_owner>(),
853 "Insufficient storage for the owner pointer type found.");
854
855 public:
856 using base = value_handler<ator_owner>;
858 using local_storage = typename base::local_storage;
859
860 static void
861 copy(any_storage& d, const any_storage& s)
862 {
863 const auto& owned(base::get_reference(s));
864
865 init_or_throw(is_copy_constructible<value_type>(), d,
866 ator_type(owned.get_allocator()), owned);
867 }
868
869 private:
870 template<typename _func>
871 static void
872 do_with_allocator(any_storage& d, any_storage& s, _func f)
873 {
874 const auto p_a(d.access<rebound_ator_type*>());
875 auto& owned(base::get_reference(s));
876
877 yassume(p_a);
878 d.~any_storage();
879 ::new(&d) any_storage;
880 f(ator_type(*p_a), owned);
881 }
882
883 public:
884 YB_ATTR_nodiscard YB_PURE static value_type*
885 get_pointer(any_storage& s) ynothrow
886 {
887 return std::addressof(get_reference(s));
888 }
889 YB_ATTR_nodiscard YB_PURE static const value_type*
890 get_pointer(const any_storage& s) ynothrow
891 {
892 return std::addressof(get_reference(s));
893 }
894
895 // NOTE: This is also used for client code (e.g. %ystdex::function).
896 // XXX: Extract it as handler traits function template or free function
897 // template?
899 YB_ATTR_nodiscard YB_PURE static value_type&
900 get_reference(any_storage& s) ynothrow
901 {
902 return base::get_reference(s).ref;
903 }
905 YB_ATTR_nodiscard YB_PURE static const value_type&
906 get_reference(const any_storage& s) ynothrow
907 {
908 return base::get_reference(s).ref;
909 }
910
912 template<typename... _tParams>
913 static auto
914 init(any_storage& d, ator_type a, _tParams&&... args)
915 -> yimpl(enable_if_t<is_constructible<value_type, _tParams&&...>::value,
916 decltype(base::init(d, std::declval<value_type&>(), a), void())>)
917 {
918 auto gd(ystdex::make_allocator_guard(a));
919
920 ator_traits::construct(a, gd.get(), yforward(args)...);
921 base::init(d, *gd.release(), a);
922 }
923
924 private:
925 template<typename... _tParams>
926 YB_NORETURN static void
927 init_or_throw(false_, _tParams&&...)
928 {
929 throw_invalid_construction();
930 }
932 template<typename... _tParams>
933 static void
934 init_or_throw(true_, any_storage& d, const ator_type& a,
935 const ator_owner& owned)
936 {
937 init(d, a, owned.ref);
938 }
940 template<typename... _tParams>
941 static void
942 init_or_throw(true_, any_storage& d, const ator_type& a,
943 ator_owner&& owned)
944 {
945 init(d, a, std::move(owned.ref));
946 }
947
948 public:
949 static void
950 manage(any_storage& d, any_storage& s, op_code op)
951 {
952 switch(op)
953 {
954 case get_type:
955 d = &ystdex::type_id<value_type>();
956 break;
957 case get_ptr:
958 d = ystdex::pvoid(get_pointer(s));
959 break;
960 case clone:
961 copy(d, s);
962 break;
963 case get_allocator_type:
964 d = &ystdex::type_id<rebound_ator_type>();
965 break;
966 case get_allocator_ptr:
967 d = static_cast<void*>(
968 std::addressof(base::get_reference(s).get_allocator()));
969 break;
970 case clone_with_allocator:
971 do_with_allocator(d, s,
972 [&](const rebound_ator_type& a, const ator_owner& owned){
973 init_or_throw(is_copy_constructible<value_type>(), d,
974 ator_type(a), owned);
975 });
976 break;
977 case transfer_with_allocator:
978 do_with_allocator(d, s,
979 [&](const rebound_ator_type& a, ator_owner& owned){
980 if(typename
981 allocator_traits<rebound_ator_type>::is_always_equal()
982 || rebound_ator_type(owned.get_allocator()) == a)
983 std::swap(d, s);
984 else
985 init_or_throw(is_move_constructible<value_type>(), d,
986 ator_type(a), std::move(owned));
987 });
988 break;
989 default:
990 base::manage(d, s, op);
991 }
992 }
993 };
994
995
1001 template<class _tByteAlloc, class _tHolder>
1002 class allocator_holder_handler
1003 : private allocator_value_handler<_tByteAlloc, _tHolder>
1004 {
1005 static_assert(check_holder_t<_tHolder>(), "Invalid holder type found.");
1006
1007 public:
1008 using holder_type = _tHolder;
1009 using base = allocator_value_handler<_tByteAlloc, _tHolder>;
1010
1011 YB_ATTR_nodiscard YB_PURE static holder_type*
1012 get_holder_pointer(any_storage& s) ynothrow
1013 {
1014 return base::get_pointer(s);
1015 }
1016
1017 using base::init;
1018
1019 static void
1020 manage(any_storage& d, any_storage& s, op_code op)
1021 {
1022 switch(op)
1023 {
1024 case get_type:
1025 d = &get_holder_pointer(s)->type();
1026 break;
1027 case get_ptr:
1028 d = ystdex::pvoid(get_holder_pointer(s)->get());
1029 break;
1030 case get_holder_type:
1031 d = &ystdex::type_id<holder_type>();
1032 break;
1033 case get_holder_ptr:
1034 d = static_cast< holder*>(get_holder_pointer(s));
1035 break;
1036 default:
1037 base::manage(d, s, op);
1038 }
1039 }
1040 };
1042
1043
1049 template<class _tAlloc, typename _type>
1051 using allocator_value_handler_t = allocator_value_handler<
1052 rebind_alloc_t<_tAlloc, byte>, _type>;
1054 template<class _tAlloc, class _tHolder>
1055 using allocator_holder_handler_t = allocator_holder_handler<
1056 rebind_alloc_t<_tAlloc, byte>, _tHolder>;
1058
1059
1065 template<typename _type>
1066 struct wrap_handler
1067 {
1069 static_assert(is_decayed<_type>(), "Invalid type found.");
1070
1071 using value_type = remove_reference_t<unwrap_reference_t<_type>>;
1073 static_assert(is_object<value_type>(), "Invalid value type found.");
1074 using type = cond_t<is_reference_wrapper<_type>, ref_handler<value_type>,
1075 value_handler<value_type>>;
1076 };
1077
1078 } // namespace any_ops;
1079
1080
1090 class YB_API bad_any_cast : public std::bad_cast
1091 {
1092 private:
1094 lref<const type_info> from_ti, to_ti;
1095
1096 public:
1098
1099 bad_any_cast()
1100 : std::bad_cast(),
1101 from_ti(ystdex::type_id<void>()), to_ti(ystdex::type_id<void>())
1102 {}
1104 bad_any_cast(const type_info& from_, const type_info& to_)
1105 : std::bad_cast(),
1106 from_ti(from_), to_ti(to_)
1107 {}
1109 bad_any_cast(const bad_any_cast&) = default;
1114 ~bad_any_cast() override;
1115
1117
1118 YB_ATTR_nodiscard YB_ATTR_returns_nonnull YB_PURE const char*
1119 from() const ynothrow;
1120
1122 YB_ATTR_nodiscard YB_PURE const type_info&
1123 from_type() const ynothrow
1124 {
1125 return from_ti.get();
1126 }
1127
1128 YB_ATTR_nodiscard YB_ATTR_returns_nonnull YB_PURE const char*
1129 to() const ynothrow;
1130
1132 YB_ATTR_nodiscard YB_PURE const type_info&
1133 to_type() const ynothrow
1134 {
1135 return to_ti.get();
1136 }
1138
1139
1140 YB_ATTR_nodiscard YB_ATTR_returns_nonnull yimpl(YB_STATELESS) virtual
1141 const char*
1142 what() const ynothrow override;
1143 };
1144
1145
1147 namespace details
1148 {
1149
1150 template<bool _vInPlace = false>
1151 struct alloc_tag : bool_<_vInPlace>
1152 {};
1153
1154 template<typename _type>
1155 using not_tag_t = nor_<is_instance_of<_type, vseq::_a<in_place_type_t>>,
1156 is_same<_type, std::allocator_arg_t>, is_same<_type, any_ops::use_holder_t>,
1157 is_instance_of<_type, vseq::_a<any_ops::with_handler_t>>,
1158 is_same<_type, alloc_tag<>>, is_same<_type, alloc_tag<true>>>;
1159
1160 template<typename _type>
1161 using decayed_not_tag_t = not_tag_t<decay_t<_type>>;
1162
1163 template<typename _type>
1164 using any_in_place_t
1165 = alloc_tag<any_ops::is_in_place_storable<decay_t<_type>>::value>;
1166
1167 } // namespace details;
1168
1169
1175 template<typename _tSelected, typename _type = void>
1177 using exclude_tag_t
1178 = enable_if_t<details::decayed_not_tag_t<_tSelected>::value, _type>;
1179
1181 template<typename... _tParams>
1182 using exclude_tagged_params_t
1183 = enable_if_t<sizeof...(_tParams) == 0 ? true : details::decayed_not_tag_t<
1184 vseq::front_t<empty_base<_tParams...>>>::value>;
1186
1187
1189 namespace details
1190 {
1191
1192 struct any_base
1193 {
1194 // NOTE: Data members are only initialized when needed. If manager is empty,
1195 // the storage is not used.
1197 mutable any_ops::any_storage storage;
1198 any_ops::any_manager manager;
1199
1200 protected:
1201 // NOTE: Even this base class is not templated, all member functions are
1202 // inlined intentionally for performance reasons (e.g. to avoid overhead of
1203 // calls across dynamic library boundaries and difficulties on
1204 // inter-procedural optimizations). This is particularly important when
1205 // %any is used to implementation some general type-erased wrappers like
1206 // %function.
1208
1209 yconstexpr
1210 any_base() ynothrow
1211 : storage(), manager()
1212 {}
1213 explicit
1214 any_base(default_init_t) ynothrow
1215 : manager()
1216 {}
1217 template<class _tHandler, typename... _tParams>
1218 explicit inline
1219 any_base(any_ops::with_handler_t<_tHandler>, _tParams&&... args)
1220 : manager(any_ops::construct<_tHandler>(storage, yforward(args)...))
1221 {}
1223 any_base(const any_base& a)
1225 : manager(a.manager)
1226 {}
1228 ~any_base() = default;
1229
1230 public:
1232 any_ops::any_storage&
1233 call(any_ops::any_storage& t, any_ops::op_code op) const
1234 {
1235 yconstraint(manager);
1236 manager(t, storage, op);
1237 return t;
1238 }
1239
1241 void
1242 checked_destroy() ynothrow
1243 {
1244 if(manager)
1245 destroy();
1246 }
1247
1248 void
1249 destroy() ynothrowv
1250 {
1251 yconstraint(manager);
1252 manager(storage, storage, any_ops::destroy);
1253 }
1254
1256
1257 YB_ATTR_nodiscard YB_ATTR_returns_nonnull YB_PURE void*
1259 get() const
1260 {
1261 const auto p(unchecked_access<void*>(default_init, any_ops::get_ptr));
1262
1263 yassume(p);
1264 return p;
1265 }
1266
1267 YB_ATTR_nodiscard YB_PURE any_ops::holder*
1268 get_holder() const
1269 {
1270 return unchecked_access<any_ops::holder*>(default_init,
1271 any_ops::get_holder_ptr);
1272 }
1274
1281 template<typename _type>
1282 YB_ATTR_nodiscard _type*
1283 get_object_ptr()
1284 {
1285 return type() == ystdex::type_id<_type>() ? static_cast<_type*>(get())
1286 : nullptr;
1287 }
1288 template<typename _type>
1289 YB_ATTR_nodiscard YB_PURE const _type*
1290 get_object_ptr() const
1291 {
1292 return type() == ystdex::type_id<_type>()
1293 ? static_cast<const _type*>(get()) : nullptr;
1294 }
1296
1298 YB_ATTR_nodiscard YB_PURE any_ops::any_storage&
1299 get_storage() const
1300 {
1301 return storage;
1302 }
1303
1305 YB_ATTR_nodiscard YB_PURE bool
1306 has_value() const ynothrow
1307 {
1308 return manager;
1309 }
1310
1311 void
1312 move_from(any_base& a) ynothrow
1313 {
1314 if(a.manager)
1315 yunseq(storage = a.storage, a.manager = {});
1316 }
1317
1318 void
1319 swap(any_base& a) ynothrow
1320 {
1321 std::swap(storage, a.storage),
1322 std::swap(manager, a.manager);
1323 }
1324
1326
1327
1329 template<typename _type>
1330 YB_ATTR_nodiscard _type*
1331 try_get_object_ptr() ynothrowv
1332 {
1333 return type() == ystdex::type_id<_type>()
1334 ? static_cast<_type*>(try_get()) : nullptr;
1335 }
1336 template<typename _type>
1337 YB_ATTR_nodiscard YB_PURE const _type*
1338 try_get_object_ptr() const ynothrowv
1339 {
1340 return type() == ystdex::type_id<_type>()
1341 ? static_cast<const _type*>(try_get()) : nullptr;
1342 }
1343
1349 YB_ATTR_nodiscard YB_PURE void*
1350 try_get() const ynothrow
1351 {
1352 try
1353 {
1354 return get();
1355 }
1356 catch(...)
1357 {}
1358 return {};
1359 }
1361
1362 YB_ATTR_nodiscard YB_PURE const type_info&
1363 type() const ynothrowv
1364 {
1365 return *unchecked_access<const type_info*>(default_init,
1366 any_ops::get_type);
1367 }
1368
1370 template<typename _type, typename... _tParams>
1371 inline _type
1372 unchecked_access(any_ops::op_code op, _tParams&&... args) const
1373 {
1374 any_ops::any_storage t;
1375 const auto gd(t.pun<_type>(yforward(args)...));
1376
1377 return unchecked_access<_type>(t, op);
1378 }
1380 template<typename _type>
1381 inline _type
1382 unchecked_access(default_init_t, any_ops::op_code op) const
1383 {
1384 any_ops::any_storage t;
1385 const auto gd(t.pun_default<_type>());
1386
1387 return unchecked_access<_type>(t, op);
1388 }
1390 template<typename _type>
1391 inline _type
1392 unchecked_access(any_ops::any_storage& t, any_ops::op_code op) const
1393 {
1394 return call(t, op).access<_type>();
1395 }
1397 };
1398
1399
1400 template<class _tAny>
1401 struct any_emplace
1402 {
1404 template<bool _vInPlace = false>
1405 using alloc_tag = details::alloc_tag<_vInPlace>;
1406 template<typename _type>
1407 using opt_in_place_t = details::any_in_place_t<_type>;
1408
1415 template<typename _type, typename... _tParams,
1416 yimpl(typename = exclude_tagged_params_t<_tParams...>)>
1417 inline decay_t<_type>&
1418 emplace(_tParams&&... args)
1419 {
1420 return emplace_within<_type>(yforward(args)...);
1421 }
1426 template<typename _type, class _tAlloc, typename... _tParams>
1427 inline decay_t<_type>&
1428 emplace(std::allocator_arg_t, const _tAlloc& a, _tParams&&... args)
1429 {
1430 return emplace_with_tag<_type>(opt_in_place_t<_type>(), a,
1431 yforward(args)...);
1432 }
1433 template<typename _type, typename _tOther, typename... _tParams>
1434 inline decay_t<_type>&
1435 emplace(std::initializer_list<_tOther> il, _tParams&&... args)
1436 {
1437 return emplace_within<_type>(il, yforward(args)...);
1438 }
1443 template<typename _type, class _tAlloc, typename _tOther,
1444 typename... _tParams>
1445 inline decay_t<_type>&
1446 emplace(std::allocator_arg_t, const _tAlloc& a,
1447 std::initializer_list<_tOther> il, _tParams&&... args)
1448 {
1449 return emplace_with_tag<_type>(opt_in_place_t<_type>(), a, il,
1450 yforward(args)...);
1451 }
1453 // NOTE: The return is similar but different to overloads above.
1455
1456 template<typename _tHolder, typename... _tParams>
1458 inline decay_t<_tHolder>&
1459 emplace(any_ops::use_holder_t, _tParams&&... args)
1460 {
1461 return emplace_within<_tHolder>(any_ops::use_holder, yforward(args)...);
1462 }
1464 template<typename _tHolder, class _tAlloc, typename... _tParams>
1465 inline decay_t<_tHolder>&
1466 emplace(std::allocator_arg_t, const _tAlloc& a, any_ops::use_holder_t,
1467 _tParams&&... args)
1468 {
1469 return emplace_with_tag<_tHolder>(opt_in_place_t<_tHolder>(), a,
1470 any_ops::use_holder, yforward(args)...);
1471 }
1473
1474 template<typename _tHandler, typename... _tParams>
1475 void
1476 emplace_with_handler(_tParams&&... args)
1477 {
1478 auto& a(static_cast<_tAny&>(*this));
1479
1480 a.checked_destroy();
1481 #if true
1482 // NOTE: This is generally more efficient.
1483 a.manager = {};
1484 a.manager = any_ops::construct<decay_t<_tHandler>>(a.storage,
1485 yforward(args)...);
1486 #else
1487 try
1488 {
1489 a.manager = any_ops::construct<decay_t<_tHandler>>(a.storage,
1490 yforward(args)...);
1491 }
1492 catch(...)
1493 {
1494 a.manager = {};
1495 throw;
1496 }
1497 #endif
1498 }
1499
1500 private:
1502
1503 template<typename _type, class _tAlloc, typename... _tParams>
1504 inline decay_t<_type>&
1505 emplace_with_tag(alloc_tag<true>, const _tAlloc&, _tParams&&... args)
1506 {
1507 return emplace_within<_type>(yforward(args)...);
1508 }
1509 template<typename _type, class _tAlloc, typename... _tParams>
1510 inline decay_t<_type>&
1511 emplace_with_tag(alloc_tag<>, const _tAlloc& a, _tParams&&... args)
1512 {
1513 emplace_with_handler<any_ops::allocator_value_handler<_tAlloc,
1514 decay_t<_type>>>(a, yforward(args)...);
1515 return unchecked_target_ref<_type>();
1516 }
1517 template<typename _type, class _tAlloc, typename _tOther,
1518 typename... _tParams>
1519 inline decay_t<_type>&
1520 emplace_with_tag(alloc_tag<>, const _tAlloc& a,
1521 std::initializer_list<_tOther> il, _tParams&&... args)
1522 {
1523 emplace_with_handler<any_ops::allocator_value_handler<_tAlloc,
1524 decay_t<_type>>>(a, il, yforward(args)...);
1525 return unchecked_target_ref<_type>();
1526 }
1527 template<typename _tHolder, class _tAlloc, typename... _tParams>
1528 inline decay_t<_tHolder>&
1529 emplace_with_tag(alloc_tag<>, const _tAlloc& a, any_ops::use_holder_t,
1530 _tParams&&... args)
1531 {
1532 emplace_with_handler<any_ops::allocator_holder_handler_t<_tAlloc,
1533 decay_t<_tHolder>>>(a, yforward(args)...);
1534 return unchecked_holder_ref<_tHolder>();
1535 }
1536
1537 template<typename _type, typename... _tParams>
1538 inline decay_t<_type>&
1539 emplace_within(_tParams&&... args)
1540 {
1541 emplace_with_handler<any_ops::value_handler<decay_t<_type>>>(
1542 yforward(args)...);
1543 return unchecked_target_ref<_type>();
1544 }
1545 template<typename _type, typename _tOther, typename... _tParams>
1546 inline decay_t<_type>&
1547 emplace_within(std::initializer_list<_tOther> il, _tParams&&... args)
1548 {
1549 emplace_with_handler<any_ops::value_handler<decay_t<_type>>>(il,
1550 yforward(args)...);
1551 return unchecked_target_ref<_type>();
1552 }
1553 template<typename _tHolder, typename... _tParams>
1554 inline decay_t<_tHolder>&
1555 emplace_within(any_ops::use_holder_t, _tParams&&... args)
1556 {
1557 emplace_with_handler<any_ops::holder_handler<decay_t<_tHolder>>>(
1558 yforward(args)...);
1559 return unchecked_holder_ref<_tHolder>();
1560 }
1561
1562 public:
1563 template<class _tHolder>
1564 YB_ATTR_nodiscard YB_PURE inline decay_t<_tHolder>&
1565 unchecked_holder_ref()
1566 {
1567 const auto p_holder(static_cast< decay_t<_tHolder>*>(
1568 static_cast<_tAny&>(*this).unchecked_get_holder()));
1569
1570 yassume(p_holder);
1571 return *p_holder;
1572 }
1574
1576 template<typename _type>
1577 YB_ATTR_nodiscard YB_PURE inline decay_t<_type>&
1578 unchecked_target_ref()
1579 {
1580 const auto p(static_cast<_tAny&>(*this).unchecked_get());
1581
1582 yassume(p);
1583 return static_cast< decay_t<_type>&>(*p);
1584 }
1585 };
1586
1587 } // namespace details;
1588
1589
1633 class YB_API any : private details::any_base, private details::any_emplace<any>
1634 {
1636 friend details::any_emplace<any>;
1637
1638 private:
1640
1641 template<bool _vInPlace = false>
1642 using alloc_tag = details::alloc_tag<_vInPlace>;
1644
1645 template<class _tHandler, typename... _tParams>
1646 using enable_with_handler_t = enable_if_t<is_constructible<
1647 any_ops::any_manager, decltype(any_ops::construct<_tHandler>(
1648 std::declval<any_ops::any_storage&>(), std::declval<_tParams>()...))>
1649 ::value>;
1650 template<class _tCtor, class _tParamsList, typename... _tParams>
1651 using is_handler_v_constructible_t = any_ops::is_handler_constructible_t<
1652 vseq::defer_apply_t<_tCtor, _tParamsList>, _tParams...>;
1653 template<class _bCond, template<typename...> class _gHandler,
1654 class _tParamsList, typename... _tParams>
1655 using enable_with_handler_params_t = enable_if_t<cond_or_t<_bCond, false_,
1656 is_handler_v_constructible_t, vseq::_a<_gHandler>, _tParamsList,
1657 _tParams...>::value>;
1658 template<typename _tParam>
1659 using is_holder_arg_t = and_<details::not_tag_t<_tParam>,
1660 any_ops::check_holder_t<_tParam>>;
1662
1663 public:
1681 template<typename _type>
1682 using opt_in_place_t = details::any_in_place_t<_type>;
1684
1685 template<class _tAlloc, typename _type>
1687 using allocated_value_handler_t = cond_t<any::opt_in_place_t<_type>,
1688 any_ops::value_handler<_type>,
1689 any_ops::allocator_value_handler_t<_tAlloc, _type>>;
1691 template<class _tAlloc, class _tHolder>
1692 using allocated_holder_handler_t = cond_t<any::opt_in_place_t<_tHolder>,
1693 any_ops::holder_handler<_tHolder>,
1694 any_ops::allocator_holder_handler_t<_tAlloc, _tHolder>>;
1696
1697
1698 // NOTE: Efficiency consideration is same to %details::any_base.
1700
1701 yconstfn
1702 any() ynothrow = default;
1704 explicit
1705 any(default_init_t) ynothrow
1706 : any_base(default_init)
1707 {}
1709
1713 template<typename _type, yimpl(typename = exclude_self_t<any, _type>,
1714 typename = exclude_tag_t<_type>)>
1715 inline
1716 any(_type&& x)
1717 : any(any_ops::with_handler_t<any_ops::value_handler<decay_t<_type>>>(),
1718 yforward(x))
1719 {}
1724 template<typename _type, class _tAlloc, yimpl(
1725 typename = exclude_self_t<any, _type>, typename = exclude_tag_t<_type>)>
1726 inline
1727 any(std::allocator_arg_t, const _tAlloc& a, _type&& x)
1728 : any(opt_in_place_t<_type>(), a, yforward(x))
1729 {}
1731
1732 template<typename _type, typename... _tParams, yimpl(typename
1733 = enable_if_t<is_constructible<decay_t<_type>, _tParams...>::value>)>
1734 explicit inline
1735 any(in_place_type_t<_type>, _tParams&&... args)
1736 : any(any_ops::with_handler_t<any_ops::value_handler<_type>>(),
1737 yforward(args)...)
1738 {}
1740 template<typename _type, class _tAlloc, typename... _tParams, yimpl(typename
1741 = enable_if_t<is_constructible<decay_t<_type>, _tParams...>::value>)>
1742 inline
1743 any(std::allocator_arg_t, const _tAlloc& a, in_place_type_t<_type>,
1744 _tParams&&... args)
1745 : any(opt_in_place_t<_type>(), a, in_place_type<_type>,
1746 yforward(args)...)
1747 {}
1749
1751 template<typename _type, typename _type2, typename... _tParams,
1753 yimpl(typename = enable_if_t<is_constructible<decay_t<_type>,
1754 std::initializer_list<_type2>&, _tParams...>::value>)>
1755 explicit inline
1756 any(in_place_type_t<_type>, std::initializer_list<_type2> il,
1757 _tParams&&... args)
1758 : any(any_ops::with_handler_t<any_ops::value_handler<_type>>(), il,
1759 yforward(args)...)
1760 {}
1762
1764 template<typename _type, typename _type2, class _tAlloc, typename...
1766 _tParams, yimpl(typename = enable_if_t<is_constructible<decay_t<_type>,
1767 std::initializer_list<_type2>&, _tParams...>::value>)>
1768 inline
1769 any(std::allocator_arg_t, const _tAlloc& a, in_place_type_t<_type>,
1770 std::initializer_list<_type2> il, _tParams&&... args)
1771 : any(opt_in_place_t<_type>(), a, in_place_type<_type>, il,
1772 yforward(args)...)
1773 {}
1775
1776
1778 template<typename _tHolder, yimpl(typename = enable_with_handler_params_t<
1779 is_holder_arg_t<_tHolder>, any_ops::holder_handler,
1780 empty_base<_tHolder>, std::unique_ptr<_tHolder>>)>
1781 inline
1782 any(any_ops::use_holder_t, std::unique_ptr<_tHolder> p)
1783 : any(any_ops::with_handler_t<any_ops::holder_handler<_tHolder>>(),
1784 std::move(p))
1785 {}
1786 template<typename _tHolder, yimpl(typename = enable_with_handler_params_t<
1787 is_holder_arg_t<decay_t<_tHolder>>, any_ops::holder_handler,
1788 empty_base<decay_t<_tHolder>>, _tHolder>)>
1789 inline
1790 any(any_ops::use_holder_t, _tHolder&& h)
1791 : any(any_ops::with_handler_t<
1792 any_ops::holder_handler<decay_t<_tHolder>>>(), yforward(h))
1793 {}
1794 template<typename _tHolder, class _tAlloc,
1795 yimpl(typename = enable_with_handler_params_t<
1796 is_holder_arg_t<decay_t<_tHolder>>, any_ops::allocator_holder_handler_t,
1797 empty_base<_tAlloc, decay_t<_tHolder>>, const _tAlloc&, _tHolder>)>
1798 inline
1799 any(std::allocator_arg_t, const _tAlloc& a, any_ops::use_holder_t,
1800 _tHolder&& h)
1801 : any(opt_in_place_t<_tHolder>(), a, any_ops::use_holder,
1802 yforward(h))
1803 {}
1804 template<typename _tHolder, typename... _tParams,
1805 yimpl(typename = enable_with_handler_params_t<is_holder_arg_t<_tHolder>,
1806 any_ops::holder_handler, empty_base<_tHolder>, _tParams...>)>
1807 inline
1808 any(any_ops::use_holder_t, in_place_type_t<_tHolder>, _tParams&&... args)
1809 : any(any_ops::with_handler_t<any_ops::holder_handler<_tHolder>>(),
1810 yforward(args)...)
1811 {}
1812 template<typename _tHolder, class _tAlloc, typename... _tParams,
1813 yimpl(typename = enable_with_handler_params_t<is_holder_arg_t<_tHolder>,
1814 any_ops::allocator_holder_handler_t, empty_base<_tAlloc, _tHolder>,
1815 const _tAlloc&, _tParams...>)>
1816 inline
1817 any(std::allocator_arg_t, const _tAlloc& a, any_ops::use_holder_t,
1818 in_place_type_t<_tHolder>, _tParams&&... args)
1819 : any(opt_in_place_t<_tHolder>(), a, any_ops::use_holder,
1820 in_place_type<_tHolder>, yforward(args)...)
1821 {}
1823 template<typename _type,
1824 yimpl(typename = exclude_tag_t<_type>, typename = enable_with_handler_t<
1825 any_ops::holder_handler<any_ops::value_holder<decay_t<_type>>>, _type>)>
1826 inline
1827 any(_type&& x, any_ops::use_holder_t)
1828 : any(any_ops::with_handler_t<any_ops::holder_handler<
1829 any_ops::value_holder<decay_t<_type>>>>(), yforward(x))
1830 {}
1831 // XXX: In the context trying instantiating
1832 // %any_ops::allocator_holder_handler_t without the lazy instantiation
1833 // protection from %enable_with_handler_t (via %vseq::defer_apply_t),
1834 // %_tAlloc shall be SFINAE-friendly. Otherwise, a parameter pack prefixed
1835 // with %std::allocator_arg_t in the calling code can render it ill-formed
1836 // because %_tAlloc is then %std::allocator_arg_t, e.g. in the constructor
1837 // 'any(any_ops::use_holder_t, in_place_type_t<_tHolder>,
1838 // _tParams&&... args)' above.
1839 template<class _tAlloc, typename _type, yimpl(typename
1840 = exclude_tag_t<_type>, typename = exclude_tag_t<_tAlloc>, typename
1841 = enable_with_handler_t<any_ops::allocator_holder_handler_t<_tAlloc,
1842 any_ops::value_holder<decay_t<_type>>>, const _tAlloc&, _type>)>
1843 inline
1844 any(std::allocator_arg_t, const _tAlloc& a, _type&& x,
1845 any_ops::use_holder_t)
1846 : any(opt_in_place_t<rebind_alloc_t<_tAlloc, any_ops::value_holder<
1847 decay_t<_type>>>>(), a, yforward(x), any_ops::use_holder)
1848 {}
1849 template<class _tHandler, typename... _tParams, yimpl(
1850 typename = enable_with_handler_t<_tHandler, _tParams...>)>
1851 explicit inline
1852 any(any_ops::with_handler_t<_tHandler> t, _tParams&&... args)
1853 : any_base(t, yforward(args)...)
1854 {}
1855 template<class _tHandler, class _tAlloc, typename... _tParams,
1856 yimpl(typename = enable_with_handler_t<_tHandler, const _tAlloc&,
1857 _tParams...>)>
1858 inline
1859 any(std::allocator_arg_t, const _tAlloc& a,
1860 any_ops::with_handler_t<_tHandler> t, _tParams&&... args)
1861 : any_base(t, a, yforward(args)...)
1862 {}
1864
1865 // XXX: SFINAE to private constructors is ignored, so they are not testable in
1866 // other constructors by %is_constructible. Conditions of SFINAE are also
1867 // omitted here. It is the responsibility of the caller to prevent the
1868 // ill-formed constructor call being instantiated.
1869 private:
1871
1872 template<class _tAlloc, typename... _tParams>
1873 inline
1874 any(alloc_tag<true>, const _tAlloc&, _tParams&&... args)
1875 : any(yforward(args)...)
1876 {}
1877 template<typename _type, class _tAlloc>
1878 inline
1879 any(alloc_tag<>, const _tAlloc& a, _type&& x)
1880 : any(any_ops::with_handler_t<any_ops::allocator_value_handler_t<
1881 _tAlloc, decay_t<_type>>>(), a, yforward(x))
1882 {}
1883 template<typename _type, class _tAlloc, typename... _tParams>
1884 inline
1885 any(alloc_tag<>, const _tAlloc& a, in_place_type_t<_type>,
1886 _tParams&&... args)
1887 : any(any_ops::with_handler_t<any_ops::allocator_value_handler_t<
1888 _tAlloc, _type>>(), a, yforward(args)...)
1889 {}
1891 template<typename _type, typename _type2, class _tAlloc, typename...
1892 _tParams>
1893 inline
1894 any(alloc_tag<>, const _tAlloc& a, in_place_type_t<_type>,
1895 std::initializer_list<_type2> il, _tParams&&... args)
1896 : any(any_ops::with_handler_t<any_ops::allocator_value_handler_t<
1897 _tAlloc, _type>>(), a, il, yforward(args)...)
1898 {}
1899 template<typename _tHolder, class _tAlloc>
1900 inline
1901 any(alloc_tag<>, const _tAlloc& a, any_ops::use_holder_t, _tHolder&& h)
1902 : any(any_ops::with_handler_t<any_ops::allocator_holder_handler_t<
1903 _tAlloc, decay_t<_tHolder>>>(), a, yforward(h))
1904 {}
1905 template<typename _tHolder, class _tAlloc, typename... _tParams>
1906 inline
1907 any(alloc_tag<>, const _tAlloc& a, any_ops::use_holder_t,
1908 in_place_type_t<_tHolder>, _tParams&&... args)
1909 : any(any_ops::with_handler_t<any_ops::allocator_holder_handler_t<
1910 _tAlloc, _tHolder>>(), a, yforward(args)...)
1911 {}
1912 template<class _tAlloc, typename _type>
1913 inline
1914 any(alloc_tag<>, const _tAlloc& a, _type&& x, any_ops::use_holder_t)
1915 : any(any_ops::with_handler_t<any_ops::allocator_holder_handler_t<
1916 _tAlloc, any_ops::value_holder<decay_t<_type>>>>(), a, yforward(x))
1917 {}
1919
1920
1921 public:
1922 any(const any& x)
1923 : any_base(x)
1924 {
1925 if(manager)
1926 manager(storage, x.storage, any_ops::clone);
1927 }
1932 template<class _tAlloc>
1933 any(std::allocator_arg_t, const _tAlloc& a, const any& x)
1934 : any_base(x)
1935 {
1936 do_alloc_init(a, x, any_ops::clone_with_allocator);
1937 }
1939
1940 any(any&& x) ynothrow
1942 : any_base(x)
1943 {
1944 move_from(x);
1945 }
1950 template<class _tAlloc>
1951 any(std::allocator_arg_t, const _tAlloc& a, any&& x)
1952 : any_base(x)
1953 {
1954 do_alloc_init(a, x, any_ops::transfer_with_allocator);
1955 x.manager = {};
1956 }
1958 ~any()
1960 {
1961 checked_destroy();
1962 }
1963
1965 template<typename _type, yimpl(typename = exclude_self_t<any, _type>,
1966 typename = exclude_tag_t<_type>)>
1967 inline any&
1968 operator=(_type&& x)
1969 {
1970 // NOTE: Avoiding of %swap is significantly more efficient with
1971 // contemporary language implementations.
1972 return *this = any(yforward(x));
1973 }
1978 any&
1979 operator=(const any& a)
1980 {
1981 // NOTE: Ditto.
1982 return *this = any(a);
1983 }
1990 any&
1991 operator=(any&& a) ynothrow
1992 {
1993 // NOTE: Ditto.
1994 checked_destroy();
1995 manager = a.manager;
1996 move_from(a);
1997 return *this;
1998 }
1999
2000 private:
2002 template<class _tAlloc>
2003 inline void
2004 do_alloc_init(const _tAlloc& a, const any& x, any_ops::op_code op)
2005 {
2006 do_alloc_init_impl(rebind_alloc_t<_tAlloc, byte>(a), x, op);
2007 }
2008
2009 template<class _tByteAlloc>
2010 void
2011 do_alloc_init_impl(const _tByteAlloc& a, const any& x, any_ops::op_code op)
2012 {
2013 static_assert(is_byte_allocator<_tByteAlloc>(),
2014 "Invalid base allocator type found.");
2015
2016 if(manager)
2017 {
2018 const auto& alloc_tp(*x.unchecked_access<const type_info*>(
2019 default_init, any_ops::get_allocator_type));
2020
2021 if(ystdex::type_id<_tByteAlloc>() == alloc_tp)
2022 {
2023 _tByteAlloc ra(a);
2024 const auto
2025 gd(storage.pun<_tByteAlloc*>(std::addressof(ra)));
2026
2027 x.call(storage, op);
2028 }
2029 else
2030 throw_allocator_mismatch_error();
2031 }
2032 }
2033
2034 public:
2036 using any_base::has_value;
2037
2039
2040
2044 YB_ATTR_nodiscard YB_PURE void*
2045 get() const
2046 {
2047 return manager ? unchecked_get() : nullptr;
2048 }
2049
2050 YB_ATTR_nodiscard YB_PURE any_ops::holder*
2051 get_holder() const
2052 {
2053 return manager ? unchecked_get_holder() : nullptr;
2054 }
2055
2063 template<typename _type>
2064 YB_ATTR_nodiscard _type*
2065 get_object_ptr()
2066 {
2067 return manager ? any_base::template get_object_ptr<_type>() : nullptr;
2068 }
2069 template<typename _type>
2070 YB_ATTR_nodiscard YB_PURE const _type*
2071 get_object_ptr() const
2072 {
2073 return manager ? any_base::template get_object_ptr<_type>() : nullptr;
2074 }
2076
2077
2083 yimpl(using) any_base::get_storage;
2084
2085 yimpl(using) any_base::call;
2087
2089 void
2090 reset() ynothrow
2091 {
2092 if(manager)
2093 {
2094 destroy();
2095 manager = {};
2096 }
2097 }
2098
2100
2101 yimpl(using) any_emplace<any>::emplace;
2103
2108 yimpl(using) any_emplace<any>::emplace_with_handler;
2110
2112
2113 void
2114 swap(any& a) ynothrow
2115 {
2116 any_base::swap(a);
2117 }
2119 friend void
2120 swap(any& x, any& y) ynothrow
2121 {
2122 x.swap(y);
2123 }
2125
2133 template<typename _type>
2134 YB_ATTR_nodiscard _type*
2135 try_get_object_ptr() ynothrow
2136 {
2137 return
2138 manager ? any_base::template try_get_object_ptr<_type>() : nullptr;
2139 }
2140 template<typename _type>
2141 YB_ATTR_nodiscard YB_PURE const _type*
2142 try_get_object_ptr() const ynothrow
2143 {
2144 return
2145 manager ? any_base::template try_get_object_ptr<_type>() : nullptr;
2146 }
2148
2150 YB_ATTR_nodiscard YB_PURE const type_info&
2151 type() const ynothrow
2152 {
2153 return manager ? unchecked_type() : ystdex::type_id<void>();
2154 }
2155
2162 yimpl(using) any_base::unchecked_access;
2164
2170 YB_ATTR_nodiscard YB_ATTR_returns_nonnull void*
2171 unchecked_get() const
2172 {
2173 return any_base::get();
2174 }
2175
2177 YB_ATTR_nodiscard YB_PURE any_ops::holder*
2178 unchecked_get_holder() const
2179 {
2180 return any_base::get_holder();
2181 }
2182
2187 YB_ATTR_nodiscard YB_PURE const type_info&
2188 unchecked_type() const ynothrowv
2189 {
2190 return any_base::type();
2191 }
2193 };
2194
2196
2197
2209 template<typename _type, typename... _tParams>
2210 YB_ATTR_nodiscard inline any
2211 make_any(_tParams&&... args)
2212 {
2213 return any(in_place_type<_type>, yforward(args)...);
2214 }
2215 template<typename _type, typename _tOther, typename... _tParams>
2216 YB_ATTR_nodiscard inline any
2217 make_any(std::initializer_list<_tOther> il, _tParams&&... args)
2218 {
2219 return any(in_place_type<_type>, il, yforward(args)...);
2220 }
2222
2239 template<typename _type>
2240 YB_ATTR_nodiscard YB_PURE _type
2241 any_cast(any& x)
2242 {
2243 using target_t = remove_cvref_t<_type>;
2244 static_assert(is_constructible<_type, target_t&>(),
2245 "Invalid cast destination type found.");
2246
2247 if(const auto p = x.template get_object_ptr<target_t>())
2248 return static_cast<_type>(*p);
2249 throw bad_any_cast(x.type(), ystdex::type_id<_type>());
2250 }
2251 template<typename _type>
2252 YB_ATTR_nodiscard YB_PURE _type
2253 any_cast(const any& x)
2254 {
2255 using target_t = remove_cvref_t<_type>;
2256 static_assert(is_constructible<_type, const target_t&>(),
2257 "Invalid cast destination type found.");
2258
2259 if(const auto p = x.template get_object_ptr<target_t>())
2260 return static_cast<_type>(*p);
2261 throw bad_any_cast(x.type(), ystdex::type_id<_type>());
2262 }
2264 template<typename _type>
2265 YB_ATTR_nodiscard YB_PURE _type
2266 any_cast(any&& x)
2267 {
2268 using target_t = remove_cvref_t<_type>;
2269 static_assert(is_constructible<_type, target_t>(),
2270 "Invalid cast destination type found.");
2271
2272 if(const auto p = x.template get_object_ptr<target_t>())
2273 return static_cast<_type>(std::move(*p));
2274 throw bad_any_cast(x.type(), ystdex::type_id<_type>());
2275 }
2277
2279 template<typename _type>
2280 YB_ATTR_nodiscard YB_PURE inline _type*
2281 any_cast(any* p) ynothrow
2282 {
2283 return p ? p->try_get_object_ptr<_type>() : nullptr;
2284 }
2285 template<typename _type>
2286 YB_ATTR_nodiscard YB_PURE inline const _type*
2287 any_cast(const any* p) ynothrow
2288 {
2289 return p ? p->try_get_object_ptr<_type>() : nullptr;
2290 }
2292
2293
2294
2304 YB_ATTR_nodiscard YB_PURE inline bool
2305 hold_same(const any& x, const any& y)
2306 {
2307 return x.get() == y.get();
2308 }
2309
2322 template<typename _type>
2323 YB_ATTR_nodiscard YB_ATTR_returns_nonnull YB_PURE inline _type*
2324 unchecked_any_cast(any* p)
2325 {
2326 // NOTE: See $2019-08 @ %Documentation::Workflow.
2327 // yconstraint(p && p->has_value());
2328 yconstraint(p);
2329 yconstraint(p->has_value());
2330 YAssert(p->unchecked_type() == ystdex::type_id<_type>(),
2331 "Invalid target type found.");
2332 return static_cast<_type*>(p->unchecked_get());
2333 }
2334 template<typename _type>
2335 YB_ATTR_nodiscard YB_ATTR_returns_nonnull YB_PURE inline const _type*
2336 unchecked_any_cast(const any* p)
2337 {
2338 // NOTE: Ditto.
2339 yconstraint(p);
2340 yconstraint(p->has_value());
2341 YAssert(p->unchecked_type() == ystdex::type_id<_type>(),
2342 "Invalid target type found.");
2343 return static_cast<const _type*>(p->unchecked_get());
2344 }
2346
2354 template<typename _type>
2355 YB_ATTR_nodiscard YB_PURE inline _type*
2356 unsafe_any_cast(any* p)
2357 {
2358 yconstraint(p);
2359 YAssert(p->unchecked_type() == ystdex::type_id<_type>(),
2360 "Invalid target type found.");
2361 return static_cast<_type*>(p->get());
2362 }
2363 template<typename _type>
2364 YB_ATTR_nodiscard YB_PURE inline const _type*
2365 unsafe_any_cast(const any* p)
2366 {
2367 yconstraint(p);
2368 YAssert(p->unchecked_type() == ystdex::type_id<_type>(),
2369 "Invalid target type found.");
2370 return static_cast<const _type*>(p->get());
2371 }
2373
2374
2375
2376
2377
2382 class YB_API void_ref_any
2383 {
2384 private:
2385 mutable any data;
2386
2387 public:
2388 void_ref_any() = default;
2389 template<typename _type,
2390 yimpl(typename = exclude_self_t<void_ref_any, _type>)>
2391 void_ref_any(_type&& x)
2392 : void_ref_any(yforward(x), is_convertible<_type&&, void_ref>())
2393 {}
2394
2395 private:
2396 template<typename _type>
2397 void_ref_any(_type&& x, true_)
2398 : data(void_ref(yforward(x)))
2399 {}
2400 template<typename _type>
2401 void_ref_any(_type&& x, false_)
2402 : data(yforward(x))
2403 {}
2404
2405 public:
2406 void_ref_any(const void_ref_any&) = default;
2407 void_ref_any(void_ref_any&&) = default;
2408
2409 void_ref_any&
2410 operator=(const void_ref_any&) = default;
2411 void_ref_any&
2412 operator=(void_ref_any&&) = default;
2413
2415 template<typename _type,
2416 yimpl(typename = exclude_self_t<void_ref_any, _type>)>
2417 YB_ATTR_nodiscard YB_PURE
2418 operator _type() const
2419 {
2420 if(data.type() == ystdex::type_id<void_ref>())
2421 return *ystdex::unchecked_any_cast<void_ref>(&data);
2422 // XXX: This is pure for emulated rvalues.
2423 return std::move(*ystdex::unchecked_any_cast<_type>(&data));
2424 }
2425 };
2426
2427 } // namespace ystdex;
2428
2429 #endif
2430
ystdex::details::any_base::manager
any_ops::any_manager manager
Definition: any.h:1198
ystdex::details::any_base::try_get_object_ptr
const _type * try_get_object_ptr() const
Definition: any.h:1338
ystdex::any::any
any(in_place_type_t< _type >, std::initializer_list< _type2 > il, _tParams &&... args)
Definition: any.h:1756
ystdex::details::any_base::swap
void swap(any_base &a)
Definition: any.h:1319
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
ystdex::any::any
any(any_ops::use_holder_t, std::unique_ptr< _tHolder > p)
构造：使用指定持有者。
Definition: any.h:1782
ystdex::any_ops::ref_handler::get_pointer
static value_type * get_pointer(any_storage &s)
Definition: any.h:660
x
const EncapsulationBase & x
Definition: NPLA1Forms.cpp:1536
ystdex::any_ops::any_trivial_local_data::mem_ptr
void *any_trivial_local_data::* mem_ptr
Definition: any.h:381
ystdex::empty_base
空基类模板。
Definition: ydef.h:1424
ystdex::cpp2017::swap
void swap(optional< _type > &x, optional< _type > &y)
Definition: optional.h:888
ystdex::details::any_base::destroy
void destroy()
Definition: any.h:1249
ystdex::any_ops::allocator_holder_handler::holder_type
_tHolder holder_type
Definition: any.h:1008
ystdex::any::any
any(std::allocator_arg_t, const _tAlloc &a, in_place_type_t< _type >, _tParams &&... args)
Definition: any.h:1743
ystdex::vseq::_a
构造具有 apply 成员的一阶元函数。
Definition: variadic.hpp:247
ystdex::vseq::defer_apply_t
_t< defer_t< _func::template apply, _tParamsList > > defer_apply_t
Definition: variadic.hpp:202
ystdex::any_ops::wrap_handler::type
cond_t< is_reference_wrapper< _type >, ref_handler< value_type >, value_handler< value_type > > type
Definition: any.h:1075
ystdex::any_ops::value_holder::value_type
_type value_type
Definition: any.h:127
ystdex::lref< const type_info >
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:1072
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
ystdex::details::any_emplace::unchecked_target_ref
decay_t< _type > & unchecked_target_ref()
Definition: any.h:1578
ystdex::any::operator=
any & operator=(any &&a)
转移赋值。
Definition: any.h:1991
ystdex::any_ops::ref_handler::manage
static void manage(any_storage &d, any_storage &s, op_code op)
Definition: any.h:696
ystdex::void_ref_any::void_ref_any
void_ref_any(_type &&x, true_)
Definition: any.h:2397
ystdex::any_ops::op_code
std::uint32_t op_code
操作码。
Definition: any.h:237
ystdex::any::any
any(alloc_tag<>, const _tAlloc &a, in_place_type_t< _type >, _tParams &&... args)
Definition: any.h:1885
ystdex::details::any_base::unchecked_access
_type unchecked_access(any_ops::any_storage &t, any_ops::op_code op) const
Definition: any.h:1392
ystdex::details::any_base::any_base
any_base(default_init_t)
Definition: any.h:1214
ystdex::throw_allocator_mismatch_error
void throw_allocator_mismatch_error()
Definition: ystdex/exception.cpp:62
ystdex::any_ops::clone_with_allocator
@ clone_with_allocator
以分配器复制。
Definition: any.h:344
ystdex::any::get_object_ptr
_type * get_object_ptr()
取目标指针。
Definition: any.h:2065
ystdex::any_ops::pointer_holder::get
void * get() const override
Definition: any.h:214
ystdex::details::any_base::has_value
bool has_value() const
Definition: any.h:1306
ystdex::details::any_base::storage
any_ops::any_storage storage
Definition: any.h:1197
ystdex::any_ops::allocator_value_handler::get_pointer
static value_type * get_pointer(any_storage &s)
Definition: any.h:885
yalignof
#define yalignof(_type)
指定特定类型的对齐。
Definition: ydef.h:1053
ystdex::details::any_emplace::emplace
decay_t< _type > & emplace(std::allocator_arg_t, const _tAlloc &a, std::initializer_list< _tOther > il, _tParams &&... args)
Definition: any.h:1446
ystdex::any_ops::value_handler::get_reference
static const value_type & get_reference(const any_storage &s)
Definition: any.h:582
ref.hpp
引用包装。
ystdex::any::any
any(alloc_tag<>, const _tAlloc &a, any_ops::use_holder_t, in_place_type_t< _tHolder >, _tParams &&... args)
Definition: any.h:1907
ystdex::any_ops::no_op
@ no_op
空操作：表示不处理的默认值。
Definition: any.h:258
ystdex::any_ops::pointer_holder::operator=
pointer_holder & operator=(const pointer_holder &)=default
ystdex::any_ops::ref_handler::init
static auto init(any_storage &d, _tWrapper x) -> decltype(base::init(d, std::addressof(x.get())))
Definition: any.h:688
ystdex::cpp2017::allocator_traits
Definition: allocator.hpp:384
ystdex::details::any_base::call
any_ops::any_storage & call(any_ops::any_storage &t, any_ops::op_code op) const
Definition: any.h:1233
ystdex::any_ops::allocator_value_handler::ator_del::ref
value_type & ref
Definition: any.h:817
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: meta.hpp:199
ystdex::details::any_emplace::emplace
decay_t< _type > & emplace(_tParams &&... args)
Definition: any.h:1418
ystdex::well_formed_t
typename always< _type >::template apply< _types... >::type well_formed_t
void_t 的一般化，可指定别名类型。
Definition: meta.hpp:275
ystdex::any_ops::value_handler::manage
static void manage(any_storage &d, any_storage &s, op_code op)
Definition: any.h:616
ystdex::any_ops::holder::holder
holder(const holder &)=default
ystdex::any::try_get_object_ptr
_type * try_get_object_ptr()
尝试取目标指针：存储目标类型和模板参数相同且不存在持有者抛出的异常。
Definition: any.h:2135
ystdex::exclude_self_params_t
enable_if_t< not_< cond_or_t< bool_< sizeof...(_tParams)==1 >, false_, is_same_param, _tSelected, _tParams... > >::value, void > exclude_self_params_t
排除选择类型的特定参数类型的重载。
Definition: type_op.hpp:295
ystdex::unchecked_any_cast
_type * unchecked_any_cast(any *p)
未检查的动态泛型转换。
Definition: any.h:2324
ystdex::any::any
any(_type &&x)
Definition: any.h:1716
ystdex::any_ops::value_handler::dispose
static void dispose(any_storage &d)
Definition: any.h:556
ystdex::any_ops::base_op
base_op
基本操作码。
Definition: any.h:253
ystdex::cpp2014::aligned_storage_t
typename aligned_storage< _vLen, _vAlign >::type aligned_storage_t
Definition: meta.hpp:187
ystdex::void_ref_any::operator=
void_ref_any & operator=(void_ref_any &&)=default
ystdex::any_ops::value_handler< _tHolder >::value_type
_tHolder value_type
Definition: any.h:533
ystdex::any::is_handler_v_constructible_t
any_ops::is_handler_constructible_t< vseq::defer_apply_t< _tCtor, _tParamsList >, _tParams... > is_handler_v_constructible_t
Definition: any.h:1652
ystdex::any_ops::construct
auto construct(any_storage &storage, _tParams &&... args) -> enable_if_t< is_convertible< well_formed_t< decltype(_tHandler::manage), decltype(_tHandler::init(storage, std::forward< decltype(args)>(args)...))>, any_manager >::value, any_manager >
使用指定处理器初始化存储。
Definition: any.h:418
ystdex::any_ops::ref_handler::get_reference
static const value_type & get_reference(const any_storage &s)
Definition: any.h:677
ystdex::any_ops::value_handler< _tHolder >::stored_type
cond_t< local_storage, value_type, memory_thunk > stored_type
Definition: any.h:544
ystdex::any::allocated_holder_handler_t
cond_t< any::opt_in_place_t< _tHolder >, any_ops::holder_handler< _tHolder >, any_ops::allocator_holder_handler_t< _tAlloc, _tHolder > > allocated_holder_handler_t
根据分配器类型和存储对象的类型取使用分配器和持有者构造时的处理器。
Definition: any.h:1694
ystdex::any::get
void * get() const
Definition: any.h:2045
CHRLib::d
_tDst * d
Definition: CharacterProcessing.h:142
ystdex::is_cv
判断指定类型是否为 const 或 volatile 类型。
Definition: meta.hpp:588
typeinfo.h
ISO C++ 类型信息扩展。
ystdex::details::any_emplace::unchecked_holder_ref
decay_t< _tHolder > & unchecked_holder_ref()
Definition: any.h:1565
ystdex::any_ops::holder_handler::manage
static void manage(any_storage &d, any_storage &s, op_code op)
Definition: any.h:764
ystdex::any_ops::value_handler::get_pointer
static value_type * get_pointer(any_storage &s)
Definition: any.h:565
ystdex::make_any
any make_any(std::initializer_list< _tOther > il, _tParams &&... args)
Definition: any.h:2217
ystdex::any_ops::value_handler::init_or_throw
static void init_or_throw(false_, _tParams &&...)
Definition: any.h:601
ystdex::details::any_base::get_object_ptr
const _type * get_object_ptr() const
Definition: any.h:1290
ystdex::any_ops
Definition: any.h:68
ystdex::is_instance_of
is_same< detected_or_t< void, details::ctor_of_or_void_t, _type >, _tCtor > is_instance_of
判断类型是否是指定类型构造器的实例。
Definition: type_op.hpp:217
ystdex::details::any_base::get_object_ptr
_type * get_object_ptr()
Definition: any.h:1283
ystdex::any_ops::allocator_value_handler::init_or_throw
static void init_or_throw(false_, _tParams &&...)
Definition: any.h:927
ystdex::is_byte_allocator
判断类型是 byte 分配器。
Definition: allocator.hpp:616
ystdex::any_ops::allocator_value_handler_t
allocator_value_handler< rebind_alloc_t< _tAlloc, byte >, _type > allocator_value_handler_t
取重绑定 byte 分配器的使用分配器构造时的处理器。
Definition: any.h:1052
ystdex::any_ops::pointer_holder::pointer_holder
pointer_holder(pointer_holder &&)=default
ystdex::any_ops::value_holder::type
const type_info & type() const override
Definition: any.h:160
ystdex::cond_or_t
_t< cond_or< _tCond, _tDefault, _gOp, _tParams... > > cond_or_t
Definition: type_op.hpp:265
ystdex::any_ops::any_local_data
能被动态泛型对象原地存储的数据类型。
Definition: any.h:391
ystdex::details::any_base::unchecked_access
_type unchecked_access(any_ops::op_code op, _tParams &&... args) const
Definition: any.h:1372
ystdex::any_ops::allocator_value_handler::get_pointer
static const value_type * get_pointer(const any_storage &s)
Definition: any.h:890
ystdex::any_ops::any_local_data::trivial
any_trivial_local_data trivial
Definition: any.h:396
ystdex::void_ref_any
Definition: any.h:2383
ystdex::any_ops::wrap_handler::value_type
remove_reference_t< unwrap_reference_t< _type > > value_type
Definition: any.h:1071
ystdex::any_ops::with_handler_t
Definition: any.h:73
ystdex::any::unchecked_type
const type_info & unchecked_type() const
取包含对象的类型。
Definition: any.h:2188
ystdex::details::any_emplace::emplace
decay_t< _type > & emplace(std::allocator_arg_t, const _tAlloc &a, _tParams &&... args)
Definition: any.h:1428
ystdex::any_ops::holder_handler
动态泛型对象持有者处理器。
Definition: any.h:722
ystdex::any_ops::details::memory_thunk::value_type
_tValue value_type
Definition: any.h:475
ystdex::bad_any_cast
动态泛型转换失败异常。
Definition: any.h:1091
CHRLib::f
f(d, s)
ystdex::bad_any_cast::to_ti
lref< const type_info > to_ti
Definition: any.h:1094
ystdex::any_ops::value_handler::copy
static void copy(any_storage &d, const any_storage &s)
Definition: any.h:550
YAssert
#define YAssert(_expr, _msg)
Definition: cassert.h:154
ystdex::any_ops::allocator_value_handler< _tByteAlloc, _tHolder >::value_type
_tHolder value_type
Definition: any.h:800
ystdex::default_init_t
默认初始化标记。
Definition: placement.hpp:150
ystdex::clone_monomorphic_ptr
auto clone_monomorphic_ptr(const _tPointer &p) -> decltype(ystdex::clone_monomorphic(*p))
若指针非空，使用 new 复制指针指向的对象。
Definition: memory.hpp:1161
ystdex::is_decayed
判断指定类型是否已退化为指定类型。
Definition: meta.hpp:672
ystdex::any_ops::details::memory_thunk::get
value_type & get() const
Definition: any.h:495
ystdex::any_ops::allocator_value_handler::init_or_throw
static void init_or_throw(true_, any_storage &d, const ator_type &a, ator_owner &&owned)
Definition: any.h:942
ystdex::any::unchecked_get_holder
any_ops::holder * unchecked_get_holder() const
取持有者指针。
Definition: any.h:2178
ystdex::bad_any_cast::bad_any_cast
bad_any_cast(const bad_any_cast &)=default
ystdex::void_ref_any::operator=
void_ref_any & operator=(const void_ref_any &)=default
ystdex::any_ops::allocator_value_handler::get_reference
static value_type & get_reference(any_storage &s)
Definition: any.h:900
ystdex::default_init
const struct ystdex::default_init_t default_init
ystdex::any_ops::pointer_holder::value_type
_type value_type
Definition: any.h:184
CHRLib::args
YB_ATTR_nodiscard _tParams && args
Definition: CharacterProcessing.h:649
ystdex::bool_
integral_constant< bool, _vInt > bool_
Definition: integral_constant.hpp:93
ystdex::details::_type2
_type2
Definition: operators.hpp:241
yassume
#define yassume(_expr)
假定：环境语义。
Definition: cassert.h:96
ystdex::standard_layout_storage
任意标准布局类型对象提供空间的存储。
Definition: type_pun.hpp:308
ystdex::any_ops::details::memory_thunk
Definition: any.h:473
ystdex::any::do_alloc_init
void do_alloc_init(const _tAlloc &a, const any &x, any_ops::op_code op)
Definition: any.h:2004
ystdex::cpp2014::decay_t
typename decay< _type >::type decay_t
Definition: meta.hpp:196
ystdex::exclude_tagged_params_t
enable_if_t< sizeof...(_tParams)==0 ? true :details::decayed_not_tag_t< vseq::front_t< empty_base< _tParams... > >>::value > exclude_tagged_params_t
排除选择类型的第一个参数为标签的重载。
Definition: any.h:1184
ystdex::standard_layout_storage::pun_default
pun_ptr< _type > pun_default()
Definition: type_pun.hpp:397
ystdex::any_ops::value_holder
值类型动态泛型持有者。
Definition: any.h:121
ystdex::any_ops::allocator_value_handler::ator_del
Definition: any.h:816
ystdex::details::any_base
Definition: any.h:1193
ystdex::any_ops::ref_handler::value_type
_type value_type
Definition: any.h:654
ystdex::any_ops::allocator_value_handler::do_with_allocator
static void do_with_allocator(any_storage &d, any_storage &s, _func f)
Definition: any.h:872
ystdex::any::allocated_value_handler_t
cond_t< any::opt_in_place_t< _type >, any_ops::value_handler< _type >, any_ops::allocator_value_handler_t< _tAlloc, _type > > allocated_value_handler_t
根据分配器类型和存储对象的类型取使用分配器构造时的处理器。
Definition: any.h:1689
ystdex::any::any
any(std::allocator_arg_t, const _tAlloc &a, _type &&x, any_ops::use_holder_t)
Definition: any.h:1844
ystdex::any_ops::holder_handler::get_holder_pointer
static holder_type * get_holder_pointer(any_storage &s)
Definition: any.h:732
ystdex::bases::nonmovable
不可转移对象：禁止继承此类的对象调用默认原型的转移构造函数和转移赋值操作符。
Definition: base.h:90
ystdex::void_ref
任意对象引用类型。
Definition: ref.hpp:271
YB_ATTR_returns_nonnull
#define YB_ATTR_returns_nonnull
指示返回非空属性。
Definition: ydef.h:761
ystdex::any_ops::value_holder::value_holder
value_holder()=default
ystdex::any_ops::allocator_holder_handler::get_holder_pointer
static holder_type * get_holder_pointer(any_storage &s)
Definition: any.h:1012
ystdex::details::any_base::try_get
void * try_get() const
取类型中立的对象指针。
Definition: any.h:1350
ystdex::any::any
any(alloc_tag<>, const _tAlloc &a, any_ops::use_holder_t, _tHolder &&h)
Definition: any.h:1901
ystdex::details::any_base::get_holder
any_ops::holder * get_holder() const
Definition: any.h:1268
ystdex::details::any_emplace::emplace_with_tag
decay_t< _tHolder > & emplace_with_tag(alloc_tag<>, const _tAlloc &a, any_ops::use_holder_t, _tParams &&... args)
Definition: any.h:1529
ystdex::details::any_emplace::emplace_with_handler
void emplace_with_handler(_tParams &&... args)
Definition: any.h:1476
ystdex::void_ref_any::void_ref_any
void_ref_any()=default
ystdex::any::any
any(const any &x)
Definition: any.h:1922
YB_NORETURN
#define YB_NORETURN
指定无返回值函数。
Definition: ydef.h:877
ystdex::any::any
any(any_ops::use_holder_t, in_place_type_t< _tHolder >, _tParams &&... args)
Definition: any.h:1808
ystdex::or_
逻辑或。
Definition: integral_constant.hpp:172
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 转发对应参数。
Definition: ydef.h:1508
ystdex::boxed_value
包装类类型的值的对象。
Definition: utility.hpp:159
ystdex::any_ops::pointer_holder::type
const type_info & type() const override
Definition: any.h:221
ystdex::any_ops::get_allocator_type
@ get_allocator_type
取重绑定到 byte 的分配器的类型。
Definition: any.h:324
ystdex::any_ops::any_trivial_local_data::obj_ptr
void * obj_ptr
Definition: any.h:378
ystdex::cpp2017::data
auto data(_tRange &c) -> decltype(c.data())
Definition: range.hpp:581
ystdex::any_ops::allocator_holder_handler::manage
static void manage(any_storage &d, any_storage &s, op_code op)
Definition: any.h:1020
ystdex::any_ops::any_local_data::allocated
aligned_storage_t< sizeof(allocated_t), std::alignment_of< allocated_t >::value > allocated
Definition: any.h:398
ystdex::any_ops::value_holder::operator=
value_holder & operator=(const value_holder &)=default
ystdex::any_ops::details::memory_thunk::p_val
std::unique_ptr< value_type > p_val
Definition: any.h:478
ystdex::details::any_base::get
void * get() const
Definition: any.h:1259
ystdex::throw_invalid_construction
void throw_invalid_construction()
Definition: ystdex/exception.cpp:49
ystdex::details::any_base::checked_destroy
void checked_destroy()
Definition: any.h:1242
ystdex::details::any_emplace::emplace
decay_t< _type > & emplace(std::initializer_list< _tOther > il, _tParams &&... args)
Definition: any.h:1435
ystdex::any::do_alloc_init_impl
void do_alloc_init_impl(const _tByteAlloc &a, const any &x, any_ops::op_code op)
Definition: any.h:2011
YB_STATELESS
#define YB_STATELESS
指示函数或函数模板实例为无状态函数。
Definition: ydef.h:941
ystdex::any::any
any(any_ops::with_handler_t< _tHandler > t, _tParams &&... args)
Definition: any.h:1852
ystdex::void_ref_any::void_ref_any
void_ref_any(void_ref_any &&)=default
std
Definition: optional.h:982
ystdex::reset
bool reset(std::unique_ptr< _type, _tDeleter > &p)
Definition: memory.hpp:613
ystdex::any::try_get_object_ptr
const _type * try_get_object_ptr() const
Definition: any.h:2142
ystdex::void_ref_any::void_ref_any
void_ref_any(_type &&x, false_)
Definition: any.h:2401
ystdex::any::any
any(alloc_tag< true >, const _tAlloc &, _tParams &&... args)
Definition: any.h:1874
ystdex::any_ops::holder::type
virtual const type_info & type() const =0
ystdex::any::any
any(_type &&x, any_ops::use_holder_t)
Definition: any.h:1827
ystdex::exclude_tag_t
enable_if_t< details::decayed_not_tag_t< _tSelected >::value, _type > exclude_tag_t
排除选择类型为标签的重载。
Definition: any.h:1178
ystdex::any::any
any()=default
ystdex::any_ops::any_manager
void(*)(any_storage &, any_storage &, op_code) any_manager
动态泛型对象管理操作。
Definition: any.h:410
memory.hpp
存储和智能指针特性。
ystdex::type_id
const type_info & type_id()
Definition: typeinfo.h:149
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1535
ystdex::any_cast
_type any_cast(any &x)
动态泛型转换。
Definition: any.h:2241
ystdex::is_reference_wrapper
判断模板参数指定的类型是否为引用包装的实例。
Definition: ref.hpp:150
utility.hpp
实用设施。
ystdex::any::make_any
any make_any(_tParams &&... args)
创建 any 对象。
Definition: any.h:2211
ystdex::any_ops::value_handler::get_pointer
static const value_type * get_pointer(const any_storage &s)
Definition: any.h:570
ystdex::rebind_alloc_t
typename allocator_traits< _tAlloc >::template rebind_alloc< _type > rebind_alloc_t
Definition: allocator.hpp:423
ystdex::any::any
any(std::allocator_arg_t, const _tAlloc &a, any &&x)
Definition: any.h:1951
ystdex::any_ops::allocator_value_handler::manage
static void manage(any_storage &d, any_storage &s, op_code op)
Definition: any.h:950
ystdex::any_ops::ref_handler::get_reference
static value_type & get_reference(any_storage &s)
Definition: any.h:671
ystdex::any_ops::pointer_holder::pointer_holder
pointer_holder(const pointer_holder &h)
Definition: any.h:201
ystdex::any_ops::allocator_value_handler::get_reference
static const value_type & get_reference(const any_storage &s)
Definition: any.h:906
ystdex::any_ops::value_handler::get_reference
static value_type & get_reference(any_storage &s)
Definition: any.h:577
yconstraint
#define yconstraint(_expr)
约束：接口语义。
Definition: cassert.h:125
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
ystdex::any_ops::get_ptr
@ get_ptr
取指向被管理的对象的指针。
Definition: any.h:275
ystdex::any_ops::allocator_value_handler::init
static auto init(any_storage &d, ator_type a, _tParams &&... args) -> enable_if_t< is_constructible< value_type, _tParams &&... >::value, decltype(base::init(d, std::declval< value_type & >(), a), void())>
Definition: any.h:914
ystdex::any_ops::value_holder::value_holder
value_holder(const value_holder &)=default
ystdex::true_
bool_< true > true_
Definition: integral_constant.hpp:109
ystdex::any::swap
friend void swap(any &x, any &y)
Definition: any.h:2120
ystdex::details::any_emplace::emplace_with_tag
decay_t< _type > & emplace_with_tag(alloc_tag< true >, const _tAlloc &, _tParams &&... args)
Definition: any.h:1505
ystdex::any_ops::get_holder_type
@ get_holder_type
取持有者的类型。
Definition: any.h:301
ystdex::unsafe_any_cast
_type * unsafe_any_cast(any *p)
非安全动态泛型转换。
Definition: any.h:2356
ystdex::details::any_emplace::emplace_within
decay_t< _type > & emplace_within(_tParams &&... args)
Definition: any.h:1539
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:143
ystdex::pvoid
enable_if_t< or_< is_object< _type >, is_void< _type > >::value, void * > pvoid(_type *p)
取 void* 类型的指针。
Definition: addressof.hpp:166
exception.h
标准库异常扩展接口。
ystdex::any_ops::allocator_value_handler::ator_del::~ator_del
~ator_del()
Definition: any.h:822
ystdex::details::any_base::any_base
any_base()
Definition: any.h:1210
ystdex::any_ops::holder_handler::init
static void init(false_, any_storage &d, std::unique_ptr< holder_type > p)
Definition: any.h:740
ystdex::cond_t
_t< cond< _tCond, _tThen, _tElse > > cond_t
Definition: meta.hpp:794
ystdex::any_ops::allocator_value_handler< _tByteAlloc, _tHolder >::ator_type
rebind_alloc_t< _tByteAlloc, _tHolder > ator_type
Definition: any.h:803
ystdex::any_ops::holder::get
virtual void * get() const =0
ystdex::any_ops::pointer_holder::pointer_holder
pointer_holder(pointer value)
初始化：取得所有权。
Definition: any.h:196
ystdex::void_ref_any::data
any data
Definition: any.h:2385
ystdex::any::any
any(in_place_type_t< _type >, _tParams &&... args)
Definition: any.h:1735
ystdex::exclude_self_t
enable_if_t<!is_same_param< _tSelected, _tParam >::value, _type > exclude_self_t
排除选择类型的特定参数的重载。
Definition: meta.hpp:865
ystdex::lref::get
_type & get() const
Definition: ref.hpp:96
ystdex::make_allocator_guard
allocator_guard< _tAlloc > make_allocator_guard(_tAlloc &a, typename allocator_traits< _tAlloc >::size_type n=1)
构造分配器守卫。
Definition: allocator.hpp:878
ystdex::details::any_emplace::emplace
decay_t< _tHolder > & emplace(std::allocator_arg_t, const _tAlloc &a, any_ops::use_holder_t, _tParams &&... args)
Definition: any.h:1466
ystdex::any::any
any(std::allocator_arg_t, const _tAlloc &a, any_ops::use_holder_t, in_place_type_t< _tHolder >, _tParams &&... args)
Definition: any.h:1817
ystdex::any::any
any(std::allocator_arg_t, const _tAlloc &a, _type &&x)
Definition: any.h:1727
YB_API
#define YB_API
YBase 应用程序编程接口：用于向库文件约定链接。
Definition: ydef.h:985
ystdex::any::any
any(std::allocator_arg_t, const _tAlloc &a, in_place_type_t< _type >, std::initializer_list< _type2 > il, _tParams &&... args)
Definition: any.h:1769
ystdex::any_ops::allocator_value_handler::copy
static void copy(any_storage &d, const any_storage &s)
Definition: any.h:861
ystdex::details::any_emplace::emplace_with_tag
decay_t< _type > & emplace_with_tag(alloc_tag<>, const _tAlloc &a, std::initializer_list< _tOther > il, _tParams &&... args)
Definition: any.h:1520
ystdex::any_ops::value_handler::init_or_throw
static void init_or_throw(true_, any_storage &d, _tParams &&... args)
Definition: any.h:608
ystdex::details::any_base::any_base
any_base(any_ops::with_handler_t< _tHandler >, _tParams &&... args)
Definition: any.h:1219
ystdex::any::any
any(std::allocator_arg_t, const _tAlloc &a, any_ops::use_holder_t, _tHolder &&h)
Definition: any.h:1799
ystdex::any_ops::pointer_holder::operator=
pointer_holder & operator=(pointer_holder &&)=default
YB_ATTR_novtable
#define YB_ATTR_novtable
修饰类定义要求实现不生成初始化动态类型信息。
Definition: ydef.h:745
ystdex::details::any_base::~any_base
~any_base()=default
ystdex::any_ops::value_handler< _tHolder >::local_storage
bool_< is_in_place_storable< _tHolder >::value > local_storage
Definition: any.h:534
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:1219
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
ystdex::bad_any_cast::bad_any_cast
bad_any_cast()
Definition: any.h:1099
ystdex::any_ops::pointer_holder::holder_pointer
_tPointer holder_pointer
Definition: any.h:185
ystdex::any::any
any(alloc_tag<>, const _tAlloc &a, _type &&x, any_ops::use_holder_t)
Definition: any.h:1914
ystdex::any_ops::details::memory_thunk::memory_thunk
memory_thunk(_tParams &&... args)
Definition: any.h:484
ystdex::any_ops::allocator_value_handler< _tByteAlloc, _tHolder >::ator_owner
ator_del ator_owner
Definition: any.h:847
ystdex::any_ops::allocator_value_handler< _tByteAlloc, _tHolder >::rebound_ator_type
rebind_alloc_t< ator_type, byte > rebound_ator_type
Definition: any.h:850
YSLib::_tParams
YB_ATTR_nodiscard YB_PURE typename _tParams
Definition: ValueNode.h:1294
ystdex::any_ops::holder_handler::init
static void init(true_, any_storage &d, std::unique_ptr< holder_type > p)
Definition: any.h:746
ystdex::details::any_emplace::emplace_with_tag
decay_t< _type > & emplace_with_tag(alloc_tag<>, const _tAlloc &a, _tParams &&... args)
Definition: any.h:1511
ystdex::any_ops::holder::holder
holder()=default
ystdex::any_ops::allocator_value_handler::ator_del::ator_del
ator_del(value_type &val, const ator_type &a)
Definition: any.h:819
ystdex::any_ops::ref_handler
动态泛型引用处理器。
Definition: any.h:652
ystdex::any::type
const type_info & type() const
Definition: any.h:2151
ystdex::any_ops::allocator_value_handler< _tByteAlloc, _tHolder >::local_storage
typename base::local_storage local_storage
Definition: any.h:858
ystdex::any_ops::any_trivial_local_data
能被动态泛型对象平凡原地存储的数据类型。
Definition: any.h:377
ystdex::any_ops::wrap_handler
根据类型选择引用或值处理器。
Definition: any.h:1067
ystdex::cpp2017::in_place_type
uniformed_tags::in_place_tag in_place_type(empty_base< _type >)
Definition: placement.hpp:255
ystdex::any_ops::get_allocator_ptr
@ get_allocator_ptr
取指向重绑定到 byte 的分配器对象的指针。
Definition: any.h:333
ystdex::any
基于类型擦除的动态泛型对象。
Definition: any.h:1634
ystdex::any_ops::get_type
@ get_type
取被管理的对象的类型。
Definition: any.h:266
ystdex::bad_any_cast::~bad_any_cast
~bad_any_cast() override
虚析构：类定义外默认实现。
ystdex::addressof
enable_if_t< has_no_overloaded_addressof< _type >::value, _type * > addressof(_type &r)
尝试对非重载 operator& 提供 constexpr 的 std::addressof 替代。
Definition: addressof.hpp:131
ystdex::any_ops::is_handler_constructible_t
is_constructible< any_ops::any_manager, decltype(any_ops::construct< _tHandler >(std::declval< any_ops::any_storage & >(), std::declval< _tParams >()...))> is_handler_constructible_t
判断处理器是否能被指定参数构造。
Definition: any.h:436
ystdex::any_ops::get_holder_ptr
@ get_holder_ptr
取指向持有者的指针。
Definition: any.h:310
ystdex::any_ops::holder_handler::init
static auto init(any_storage &d, std::unique_ptr< holder_type > p) -> decltype(init(typename base::local_storage(), d, std::move(p)), void())
Definition: any.h:754
ystdex::any_ops::any_trivial_local_data::const_obj_ptr
const void * const_obj_ptr
Definition: any.h:379
ystdex::details::any_base::move_from
void move_from(any_base &a)
Definition: any.h:1312
ystdex::details::any_base::type
const type_info & type() const
Definition: any.h:1363
ystdex::any_ops::value_holder::value_holder
value_holder(_tParam &&arg)
Definition: any.h:134
ystdex::any_ops::pointer_holder::p_held
holder_pointer p_held
Definition: any.h:189
ystdex::any::enable_with_handler_params_t
enable_if_t< cond_or_t< _bCond, false_, is_handler_v_constructible_t, vseq::_a< _gHandler >, _tParamsList, _tParams... >::value > enable_with_handler_params_t
Definition: any.h:1657
ystdex::any::any
any(alloc_tag<>, const _tAlloc &a, _type &&x)
Definition: any.h:1879
ystdex::any::any
any(std::allocator_arg_t, const _tAlloc &a, any_ops::with_handler_t< _tHandler > t, _tParams &&... args)
Definition: any.h:1859
ystdex::any_ops::destroy
@ destroy
销毁被管理的对象。
Definition: any.h:292
ystdex::details::any_base::unchecked_access
_type unchecked_access(default_init_t, any_ops::op_code op) const
Definition: any.h:1382
ystdex::any_ops::end_base_op
@ end_base_op
结束操作标记。
Definition: any.h:366
ystdex::any::any
any(alloc_tag<>, const _tAlloc &a, in_place_type_t< _type >, std::initializer_list< _type2 > il, _tParams &&... args)
Definition: any.h:1894
ystdex::cpp2014::remove_reference_t
typename remove_reference< _type >::type remove_reference_t
Definition: meta.hpp:155
ystdex::cpp2014::make_unique
enable_if_t<!is_array< _type >::value, std::unique_ptr< _type > > make_unique(_tParams &&... args)
Definition: memory.hpp:760
ystdex::any_ops::value_holder::value_holder
value_holder(value_holder &&)=default
ystdex::any::any
any(any_ops::use_holder_t, _tHolder &&h)
Definition: any.h:1790
platform::p
return p p
Definition: YCLib/FileSystem.h:209
ystdex::vseq::front_t
_t< front< _tSeq, _tEnabler > > front_t
Definition: variadic.hpp:430
ystdex::any::enable_with_handler_t
enable_if_t< is_constructible< any_ops::any_manager, decltype(any_ops::construct< _tHandler >(std::declval< any_ops::any_storage & >(), std::declval< _tParams >()...))> ::value > enable_with_handler_t
Definition: any.h:1649
ystdex::any_ops::holder
抽象动态泛型持有者接口。
Definition: any.h:82
ystdex::any_ops::use_holder_t
使用持有者标记。
Definition: any.h:453
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:413
ystdex::any_ops::holder::~holder
virtual ~holder()
虚析构：类定义外默认实现。
ystdex::details::alloc_tag
Definition: any.h:1152
platform::bool
YB_ATTR_nodiscard std::FILE *fp bool
Definition: FileIO.h:1271
ystdex::any_ops::use_holder
const struct ystdex::any_ops::use_holder_t use_holder
ystdex::any_ops::allocator_value_handler
分配器处理器。
Definition: any.h:794
ystdex::false_
bool_< false > false_
Definition: integral_constant.hpp:110
ystdex::any::get_holder
any_ops::holder * get_holder() const
Definition: any.h:2051
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:1199
ystdex::bad_any_cast::bad_any_cast
bad_any_cast(const type_info &from_, const type_info &to_)
Definition: any.h:1104
ystdex::bases::noncopyable
不可复制对象：禁止派生类调用默认原型的复制构造函数和复制赋值操作符。
Definition: base.h:50
ystdex::any_ops::pointer_holder::pointer
typename holder_pointer::pointer pointer
Definition: any.h:186
ystdex::any::get_object_ptr
const _type * get_object_ptr() const
Definition: any.h:2071
ystdex::any_ops::any_storage
standard_layout_storage< aligned_storage_t< sizeof(any_local_data), std::alignment_of< any_local_data >::value > > any_storage
Definition: any.h:405
ynoexcept
#define ynoexcept(...)
YSLib 无异常抛出保证：指定特定的异常规范。
Definition: ydef.h:1151
ystdex::details::any_emplace::emplace
decay_t< _tHolder > & emplace(any_ops::use_holder_t, _tParams &&... args)
Definition: any.h:1459
ystdex::any_ops::ref_handler::get_pointer
static const value_type * get_pointer(const any_storage &s)
Definition: any.h:665
ystdex::any_ops::value_holder::operator=
value_holder & operator=(value_holder &&)=default
ystdex::is_aligned_storable
判断是否可对齐存储。
Definition: type_pun.hpp:74
NPL::get
PDefH(void, LiftTermRef, TermNode &term, const TermNode &tm) ImplExpr(NPL ref get()
Definition: NPLA.h:1737
ystdex::ref
void ref(const _type &&)=delete
ystdex::any_ops::transfer_with_allocator
@ transfer_with_allocator
以分配器转移。
Definition: any.h:358
ystdex::any_ops::any_local_data::allocated_t
std::unique_ptr< int, allocator_delete< std::allocator< int > > > allocated_t
Definition: any.h:394
ystdex::remove_cvref_t
_t< remove_cvref< _type > > remove_cvref_t
Definition: meta.hpp:236
ystdex::any_ops::allocator_holder_handler_t
allocator_holder_handler< rebind_alloc_t< _tAlloc, byte >, _tHolder > allocator_holder_handler_t
取重绑定 byte 分配器的使用分配器和持有者构造时的处理器。
Definition: any.h:1056
ystdex::void_ref_any::void_ref_any
void_ref_any(const void_ref_any &)=default
ystdex::any_ops::value_handler::init
static enable_if_t< is_constructible< value_type, _tParams... >::value > init(any_storage &d, _tParams &&... args)
Definition: any.h:592
ystdex::details::any_base::try_get_object_ptr
_type * try_get_object_ptr()
Definition: any.h:1331
ystdex::hold_same
bool hold_same(const any &x, const any &y)
判断是否持有相同对象。
Definition: any.h:2305
ystdex::details::any_base::get_storage
any_ops::any_storage & get_storage() const
Definition: any.h:1299
ystdex::void_ref_any::void_ref_any
void_ref_any(_type &&x)
Definition: any.h:2391
ystdex::cpp2017::as_const
add_const_t< _type > & as_const(_type &t)
转换 const 引用。
Definition: utility.hpp:77
ystdex::any_ops::value_handler
动态泛型对象值处理器。
Definition: any.h:524
ystdex::details::any_emplace::emplace_within
decay_t< _tHolder > & emplace_within(any_ops::use_holder_t, _tParams &&... args)
Definition: any.h:1555
ystdex::any::any
any(std::allocator_arg_t, const _tAlloc &a, const any &x)
Definition: any.h:1933
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073
ystdex::details::any_emplace::emplace_within
decay_t< _type > & emplace_within(std::initializer_list< _tOther > il, _tParams &&... args)
Definition: any.h:1547
ystdex::allocator_delete
释放分配器分配的对象的删除器。
Definition: allocator.hpp:822
ystdex::any_ops::holder_handler::holder_type
_tHolder holder_type
Definition: any.h:727
ystdex::any_ops::value_holder::get
void * get() const override
Definition: any.h:153
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:168
NPL::_tParam
_tParam
Definition: NPLA.h:2367
ystdex::any_ops::pointer_holder
指针类型动态泛型持有者。
Definition: any.h:178
ystdex::any::operator=
any & operator=(_type &&x)
Definition: any.h:1968
ystdex::any_ops::allocator_holder_handler
使用分配器的动态泛型对象持有者处理器。
Definition: any.h:1004
ystdex::any_ops::clone
@ clone
复制被管理的对象的处理器。
Definition: any.h:285
ystdex::nor_
逻辑或非。
Definition: integral_constant.hpp:207
ystdex::any_ops::allocator_value_handler::init_or_throw
static void init_or_throw(true_, any_storage &d, const ator_type &a, const ator_owner &owned)
Definition: any.h:934
ystdex::details::any_emplace
Definition: any.h:1402
ystdex::any::operator=
any & operator=(const any &a)
复制赋值：使用复制和交换。
Definition: any.h:1979
ystdex::and_
逻辑操作元函数。
Definition: integral_constant.hpp:151
ystdex::standard_layout_storage::pun
pun_ptr< _type > pun(_tParams &&... args)
Definition: type_pun.hpp:389