YSTest: any.h 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

any.h
浏览该文件的文档.
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
31 #ifndef YB_INC_ystdex_any_h_
32 #define YB_INC_ystdex_any_h_ 1
33
34 #include "typeinfo.h" // for "typeinfo.h", cloneable, type_id_info,
35 // ystdex::type_id, std::bad_cast;
36 #include <memory> // for std::addressof, std::unique_ptr;
37 #include "utility.hpp" // "utility.hpp", for boxed_value,
38 // standard_layout_storage, aligned_storage_t, is_aligned_storable,
39 // exclude_self_t, enable_if_t, decay_t, yconstraint;
40 #include "ref.hpp" // for is_reference_wrapper, unwrap_reference_t;
41
42 namespace ystdex
43 {
44
51 namespace any_ops
52 {
53
55
56 class YB_API invalid_construction : public std::invalid_argument
58 {
59 public:
60 invalid_construction();
62 invalid_construction(const invalid_construction&) = default;
63
68 ~invalid_construction() override;
69 };
70
76 YB_NORETURN YB_API void
77 throw_invalid_construction();
79
80
82 template<typename>
83 struct in_place_t
84 {};
85
86
88 template<typename>
89 struct with_handler_t
90 {};
91
92
97 class YB_API holder : public cloneable
98 {
99 public:
101
102 holder() = default;
103 holder(const holder&) = default;
105 ~holder() override;
107
109 virtual void*
110 get() const = 0;
111
112 virtual holder*
113 clone() const override = 0;
114
116 virtual const type_info&
117 type() const ynothrow = 0;
118 };
119
120
126 template<typename _type>
127 class value_holder : protected boxed_value<_type>, public holder
128 {
129 static_assert(is_object<_type>(), "Non-object type found.");
130 static_assert(!is_cv<_type>(), "Cv-qualified type found.");
131
132 public:
134 using value_type = _type;
135
137
138 value_holder() = default;
139 template<typename _tParam,
140 yimpl(typename = exclude_self_t<value_holder, _tParam>)>
141 value_holder(_tParam&& arg)
142 ynoexcept(is_nothrow_constructible<_type, _tParam&&>())
143 : boxed_value<_type>(yforward(arg))
144 {}
145 using boxed_value<_type>::boxed_value;
147
149 value_holder(const value_holder&) = default;
150 value_holder(value_holder&&) = default;
151
152 value_holder&
153 operator=(const value_holder&) = default;
154 value_holder&
155 operator=(value_holder&&) = default;
157
158 value_holder*
159 clone() const override
160 {
161 return new value_holder(this->value);
162 }
163
165 void*
166 get() const override
167 {
168 return std::addressof(this->value);
169 }
170
172 const type_info&
173 type() const ynothrow override
174 {
175 return ystdex::type_id<_type>();
176 }
177 };
178
179
188 template<typename _type, class _tPointer = std::unique_ptr<_type>>
189 class pointer_holder : public holder
190 {
192 static_assert(is_object<_type>(), "Invalid type found.");
193
194 public:
196 using value_type = _type;
197 using holder_pointer = _tPointer;
198 using pointer = typename holder_pointer::pointer;
199
200 protected:
201 holder_pointer p_held;
202
203 public:
205 pointer_holder(pointer value)
206 : p_held(value)
207 {}
209
210 pointer_holder(const pointer_holder& h)
211 : pointer_holder(h.p_held ? new value_type(*h.p_held) : nullptr)
212 {}
213 pointer_holder(pointer_holder&&) = default;
215
216 pointer_holder&
217 operator=(const pointer_holder&) = default;
218 pointer_holder&
219 operator=(pointer_holder&&) = default;
220
221 pointer_holder*
222 clone() const override
223 {
224 return new pointer_holder(*this);
225 }
226
228 void*
229 get() const override
230 {
231 return p_held.get();
232 }
233
235 const type_info&
236 type() const ynothrow override
237 {
238 return p_held ? ystdex::type_id<_type>() : ystdex::type_id<void>();
239 }
240 };
241
242
244 using op_code = std::uint32_t;
245
247 enum base_op : op_code
248 {
250 no_op,
251 get_type,
252 get_ptr,
253 clone,
254 destroy,
255 get_holder_type,
256 get_holder_ptr,
258 end_base_op
259 };
260
261
263 using any_storage
264 = standard_layout_storage<aligned_storage_t<sizeof(void*), sizeof(void*)>>;
266 using any_manager = void(*)(any_storage&, any_storage&, op_code);
267
272 template<class _tHandler, typename... _tParams>
273 any_manager
274 construct(any_storage& storage, _tParams&&... args)
275 {
276 _tHandler::init(storage, yforward(args)...);
277 return _tHandler::manage;
278 }
279
280
285 yconstexpr const struct use_holder_t{} use_holder{};
286
287
292 template<typename _type,
293 bool _bStoredLocally = and_<is_nothrow_move_constructible<_type>,
294 is_aligned_storable<any_storage, _type>>::value>
295 class value_handler
296 {
297 public:
299
300 using value_type = _type;
301 using local_storage = bool_constant<_bStoredLocally>;
303
305
306 static void
307 copy(any_storage& d, const any_storage& s)
308 {
309 try_init(is_copy_constructible<value_type>(), local_storage(), d,
310 get_reference(s));
311 }
312
313 static void
314 dispose(any_storage& d) ynothrowv
315 {
316 dispose_impl(local_storage(), d);
317 }
318
319 private:
320 static void
321 dispose_impl(false_type, any_storage& d) ynothrowv
322 {
323 delete d.access<value_type*>();
324 }
325 static void
326 dispose_impl(true_type, any_storage& d) ynothrowv
327 {
328 d.access<value_type>().~value_type();
329 }
331
332 public:
334
335 static value_type*
336 get_pointer(any_storage& s)
337 {
338 return get_pointer_impl(local_storage(), s);
339 }
340 static const value_type*
341 get_pointer(const any_storage& s)
342 {
343 return get_pointer_impl(local_storage(), s);
344 }
345
346 private:
347 static value_type*
348 get_pointer_impl(false_type, any_storage& s)
349 {
350 return s.access<value_type*>();
351 }
352 static const value_type*
353 get_pointer_impl(false_type, const any_storage& s)
354 {
355 return s.access<const value_type*>();
356 }
357 static value_type*
358 get_pointer_impl(true_type, any_storage& s)
359 {
360 return std::addressof(get_reference_impl(true_type(), s));
361 }
362 static const value_type*
363 get_pointer_impl(true_type, const any_storage& s)
364 {
365 return std::addressof(get_reference_impl(true_type(), s));
366 }
367
368 public:
369 static value_type&
370 get_reference(any_storage& s)
371 {
372 return get_reference_impl(local_storage(), s);
373 }
374 static const value_type&
375 get_reference(const any_storage& s)
376 {
377 return get_reference_impl(local_storage(), s);
378 }
379
380 private:
381 static value_type&
382 get_reference_impl(false_type, any_storage& s)
383 {
384 const auto p(get_pointer_impl(false_type(), s));
385
386 yassume(p);
387 return *p;
388 }
389 static const value_type&
390 get_reference_impl(false_type, const any_storage& s)
391 {
392 const auto p(get_pointer_impl(false_type(), s));
393
394 yassume(p);
395 return *p;
396 }
397 static value_type&
398 get_reference_impl(true_type, any_storage& s)
399 {
400 return s.access<value_type>();
401 }
402 static const value_type&
403 get_reference_impl(true_type, const any_storage& s)
404 {
405 return s.access<const value_type>();
406 }
408
409 public:
411
412 template<typename... _tParams>
413 static void
414 init(any_storage& d, _tParams&&... args)
415 {
416 init_impl(local_storage(), d, yforward(args)...);
417 }
418
419 private:
420 template<typename... _tParams>
421 static YB_ATTR(always_inline) void
422 init_impl(false_type, any_storage& d, _tParams&&... args)
423 {
424 d = new value_type(yforward(args)...);
425 }
426 template<typename... _tParams>
427 static YB_ATTR(always_inline) void
428 init_impl(true_type, any_storage& d, _tParams&&... args)
429 {
430 new(d.access()) value_type(yforward(args)...);
431 }
433
434 public:
436 static void
437 manage(any_storage& d, any_storage& s, op_code op)
438 {
439 switch(op)
440 {
441 case get_type:
442 d = &ystdex::type_id<value_type>();
443 break;
444 case get_ptr:
445 d = get_pointer(s);
446 break;
447 case clone:
448 copy(d, s);
449 break;
450 case destroy:
451 dispose(d);
452 break;
453 case get_holder_type:
454 d = &ystdex::type_id<void>();
455 break;
456 case get_holder_ptr:
457 d = static_cast< holder*>(nullptr);
458 }
459 }
460
461 private:
463
464 template<typename... _tParams>
465 YB_NORETURN static YB_ATTR(always_inline) void
466 try_init(false_type, _tParams&&...)
467 {
468 throw_invalid_construction();
469 }
470 template<class _bInPlace, typename... _tParams>
471 static YB_ATTR(always_inline) void
472 try_init(true_type, _bInPlace b, any_storage& d, _tParams&&... args)
473 {
474 init_impl(b, d, yforward(args)...);
475 }
477 };
478
479
484 template<typename _type>
485 class ref_handler : public value_handler<_type*>
486 {
487 public:
488 using value_type = _type;
489 using base = value_handler<value_type*>;
490
492 static value_type*
493 get_pointer(any_storage& s)
494 {
495 return base::get_reference(s);
496 }
497
499 static value_type&
500 get_reference(any_storage& s)
501 {
502 yassume(get_pointer(s));
503 return *get_pointer(s);
504 }
505
507 template<typename _tWrapper,
508 yimpl(typename = enable_if_t<is_reference_wrapper<_tWrapper>::value>)>
509 static auto
510 init(any_storage& d, _tWrapper x)
511 -> decltype(base::init(d, std::addressof(x.get())))
512 {
513 base::init(d, std::addressof(x.get()));
514 }
515
517 static void
518 manage(any_storage& d, any_storage& s, op_code op)
519 {
520 switch(op)
521 {
522 case get_type:
523 d = &ystdex::type_id<value_type>();
524 break;
525 case get_ptr:
526 d = get_pointer(s);
527 break;
528 default:
529 base::manage(d, s, op);
530 }
531 }
532 };
533
534
539 template<typename _tHolder>
540 class holder_handler : public value_handler<_tHolder>
541 {
542 static_assert(is_convertible<_tHolder&, holder&>(),
543 "Invalid holder type found.");
544
545 public:
546 using value_type = typename _tHolder::value_type;
547 using base = value_handler<_tHolder>;
548
550 static _tHolder*
551 get_holder_pointer(any_storage& s)
552 {
553 return base::get_pointer(s);
554 }
555
556 static value_type*
557 get_pointer(any_storage& s)
558 {
559 const auto p(get_holder_pointer(s));
560
561 yassume(p);
562 return static_cast< value_type*>(p->_tHolder::get());
563 }
564
565 private:
567 static void
568 init(true_type, any_storage& d, std::unique_ptr<_tHolder> p)
569 {
570 new(d.access()) _tHolder(std::move(*p));
571 }
573 static void
574 init(false_type, any_storage& d, std::unique_ptr<_tHolder> p)
575 {
576 d = p.release();
577 }
578
579 public:
581 static void
582 init(any_storage& d, std::unique_ptr<_tHolder> p)
583 {
584 init(typename base::local_storage(), d, std::move(p));
585 }
587 using base::init;
588
590 static void
591 manage(any_storage& d, any_storage& s, op_code op)
592 {
593 switch(op)
594 {
595 case get_type:
596 d = &ystdex::type_id<value_type>();
597 break;
598 case get_ptr:
599 d = get_pointer(s);
600 break;
601 case get_holder_type:
602 d = &ystdex::type_id<_tHolder>();
603 break;
604 case get_holder_ptr:
605 d = static_cast< holder*>(get_holder_pointer(s));
606 break;
607 default:
608 base::manage(d, s, op);
609 }
610 }
611 };
612
613 } // namespace any_ops;
614
615
623 template<typename _type>
624 using is_any_cast_dest = or_<is_reference<_type>, is_copy_constructible<_type>>;
625
626
636 class YB_API bad_any_cast : public std::bad_cast
637 {
638 private:
640 lref<const type_info> from_ti, to_ti;
641
642 public:
644
645 bad_any_cast()
646 : std::bad_cast(),
647 from_ti(ystdex::type_id<void>()), to_ti(ystdex::type_id<void>())
648 {}
650 bad_any_cast(const type_info& from_, const type_info& to_)
651 : std::bad_cast(),
652 from_ti(from_), to_ti(to_)
653 {}
655 bad_any_cast(const bad_any_cast&) = default;
660 ~bad_any_cast() override;
661
663
664 YB_ATTR_returns_nonnull const char*
665 from() const ynothrow;
666
668 const type_info&
669 from_type() const ynothrow
670 {
671 return from_ti.get();
672 }
673
674 YB_ATTR_returns_nonnull const char*
675 to() const ynothrow;
676
678 const type_info&
679 to_type() const ynothrow
680 {
681 return to_ti.get();
682 }
684
685
686 virtual YB_ATTR_returns_nonnull const char*
687 what() const ynothrow override;
688 };
689
690
692 namespace details
693 {
694
695 struct any_base
696 {
698 mutable any_ops::any_storage storage{};
699 any_ops::any_manager manager{};
700
701 any_base() = default;
702 template<class _tHandler, typename... _tParams>
703 inline
704 any_base(any_ops::with_handler_t<_tHandler>, _tParams&&... args)
705 : manager(any_ops::construct<_tHandler>(storage, yforward(args)...))
706 {}
707
708 YB_API any_ops::any_storage&
709 call(any_ops::any_storage&, any_ops::op_code) const;
710
711 YB_API void
712 clear() ynothrowv;
713
714 void
715 copy(const any_base&);
716
717 void
718 destroy() ynothrowv;
719
720 bool
721 empty() const ynothrow
722 {
723 return !manager;
724 }
725
727
728 YB_API void*
729 get() const ynothrowv;
730
731 YB_API any_ops::holder*
732 get_holder() const;
733
735 any_ops::any_storage&
736 get_storage() const
737 {
738 return storage;
739 }
740
741 YB_API void
742 swap(any_base&) ynothrow;
743
744 template<typename _type>
745 _type*
746 target() ynothrowv
747 {
748 return type() == ystdex::type_id<_type>() ? static_cast<_type*>(get())
749 : nullptr;
750 }
751 template<typename _type>
752 const _type*
753 target() const ynothrowv
754 {
755 return type() == ystdex::type_id<_type>()
756 ? static_cast<const _type*>(get()) : nullptr;
757 }
758
759 YB_API const type_info&
760 type() const ynothrowv;
761
763 template<typename _type>
764 inline _type
765 unchecked_access(any_ops::op_code op) const
766 {
767 any_ops::any_storage t;
768
769 return unchecked_access<_type>(t, op);
770 }
772 template<typename _type>
773 inline _type
774 unchecked_access(any_ops::any_storage& t, any_ops::op_code op) const
775 {
776 return call(t, op).access<_type>();
777 }
779 };
780
781
782 template<class _tAny>
783 struct any_emplace
784 {
785 template<typename _type, typename... _tParams>
786 void
787 emplace(_tParams&&... args)
788 {
789 emplace_with_handler<any_ops::value_handler<decay_t<_type>>>(
790 yforward(args)...);
791 }
792 template<typename _tHolder, typename... _tParams>
793 void
794 emplace(any_ops::use_holder_t, _tParams&&... args)
795 {
796 emplace_with_handler<any_ops::holder_handler<decay_t<_tHolder>>>(
797 yforward(args)...);
798 }
799
800 template<typename _tHandler, typename... _tParams>
801 void
802 emplace_with_handler(_tParams&&... args)
803 {
804 auto& a(static_cast<_tAny&>(*this));
805
806 a.clear();
807 a.manager = any_ops::construct<decay_t<_tHandler>>(yforward(args)...);
808 }
809 };
810
811 } // namespace details;
812
813
823 class YB_API any : private details::any_base, private details::any_emplace<any>
824 {
825 public:
827 any() ynothrow = default;
829 template<typename _type, yimpl(typename = exclude_self_t<any, _type>,
830 typename = enable_if_t<!is_reference_wrapper<decay_t<_type>>::value>)>
831 inline
832 any(_type&& x)
833 : any(any_ops::with_handler_t<
834 any_ops::value_handler<decay_t<_type>>>(), yforward(x))
835 {}
837
838 template<typename _type, yimpl(typename
840 = enable_if_t<is_reference_wrapper<decay_t<_type>>::value>)>
841 inline
842 any(_type&& x)
843 : any(any_ops::with_handler_t<
844 any_ops::ref_handler<unwrap_reference_t<decay_t<_type>>>>(), x)
845 {}
847 template<typename _type, typename... _tParams>
848 inline
849 any(any_ops::in_place_t<_type>, _tParams&&... args)
850 : any(any_ops::with_handler_t<
851 any_ops::value_handler<_type>>(), yforward(args)...)
852 {}
858 template<typename _tHolder>
859 inline
860 any(any_ops::use_holder_t, std::unique_ptr<_tHolder> p)
861 : any(any_ops::with_handler_t<
862 any_ops::holder_handler<_tHolder>>(), std::move(p))
863 {}
864 template<typename _tHolder>
865 inline
866 any(any_ops::use_holder_t, _tHolder&& h)
867 : any(any_ops::with_handler_t<
868 any_ops::holder_handler<decay_t<_tHolder>>>(), yforward(h))
869 {}
870 template<typename _tHolder, typename... _tParams>
871 inline
872 any(any_ops::use_holder_t, any_ops::in_place_t<_tHolder>,
873 _tParams&&... args)
874 : any(any_ops::with_handler_t<any_ops::holder_handler<_tHolder>>(),
875 yforward(args)...)
876 {}
878 template<typename _type>
879 inline
880 any(_type&& x, any_ops::use_holder_t)
881 : any(any_ops::with_handler_t<any_ops::holder_handler<
882 any_ops::value_holder<decay_t<_type>>>>(), yforward(x))
883 {}
885 template<class _tHandler, typename... _tParams>
886 inline
887 any(any_ops::with_handler_t<_tHandler> t, _tParams&&... args)
888 : any_base(t, yforward(args)...)
889 {}
891 any(const any&);
892 any(any&& a) ynothrow
893 : any()
894 {
895 a.swap(*this);
896 }
898 ~any();
899
901 template<typename _type, yimpl(typename = exclude_self_t<any, _type>)>
902 any&
903 operator=(_type&& x)
904 {
905 any(yforward(x)).swap(*this);
906 return *this;
907 }
912 any&
913 operator=(const any& a)
914 {
915 any(a).swap(*this);
916 return *this;
917 }
922 any&
923 operator=(any&& a) ynothrow
924 {
925 any(std::move(a)).swap(*this);
926 return *this;
927 }
928
930 using any_base::empty;
931
933
934 void*
936 get() const ynothrow
937 {
938 return manager ? unchecked_get() : nullptr;
939 }
940
941 any_ops::holder*
942 get_holder() const
943 {
944 return manager ? unchecked_get_holder() : nullptr;
945 }
947
948 protected:
954 using any_base::get_storage;
955
956 using any_base::call;
958
959 public:
960 void
961 clear() ynothrow;
962
968 using any_emplace<any>::emplace;
969
970 using any_emplace<any>::emplace_with_handler;
972
973 void
974 swap(any& a) ynothrow
975 {
976 any_base::swap(a);
977 }
978
986 template<typename _type>
987 _type*
988 target() ynothrow
989 {
990 return manager ? any_base::template target<_type>() : nullptr;
991 }
992 template<typename _type>
993 const _type*
994 target() const ynothrow
995 {
996 return manager ? any_base::template target<_type>() : nullptr;
997 }
999
1001 const type_info&
1002 type() const ynothrow
1003 {
1004 return manager ? unchecked_type() : ystdex::type_id<void>();
1005 }
1006
1013 protected:
1015 using any_base::unchecked_access;
1016
1017 public:
1019 void*
1020 unchecked_get() const ynothrowv
1021 {
1022 return any_base::get();
1023 }
1024
1026 any_ops::holder*
1027 unchecked_get_holder() const
1028 {
1029 return any_base::get_holder();
1030 }
1031
1036 const type_info&
1037 unchecked_type() const ynothrowv
1038 {
1039 return any_base::type();
1040 }
1042 };
1043
1045
1046
1048
1052 inline void
1053 swap(any& x, any& y) ynothrow
1054 {
1055 x.swap(y);
1056 }
1057
1069
1070 template<typename _type>
1071 inline _type*
1072 any_cast(any* p) ynothrow
1073 {
1074 return p ? p->target<_type>() : nullptr;
1075 }
1076 template<typename _type>
1077 inline const _type*
1078 any_cast(const any* p) ynothrow
1079 {
1080 return p ? p->target<_type>() : nullptr;
1081 }
1083
1088 template<typename _tValue>
1089 _tValue
1090 any_cast(any& x)
1091 {
1092 static_assert(is_any_cast_dest<_tValue>(),
1093 "Invalid cast destination type found.");
1094
1095 if(const auto p = x.template target<remove_reference_t<_tValue>>())
1096 return static_cast<_tValue>(*p);
1097 throw bad_any_cast(x.type(), ystdex::type_id<_tValue>());
1098 }
1099 template<typename _tValue>
1100 _tValue
1101 any_cast(const any& x)
1102 {
1103 static_assert(is_any_cast_dest<_tValue>(),
1104 "Invalid cast destination type found.");
1105
1106 if(const auto p = x.template target<const remove_reference_t<_tValue>>())
1107 return static_cast<_tValue>(*p);
1108 throw bad_any_cast(x.type(), ystdex::type_id<_tValue>());
1109 }
1111 template<typename _tValue>
1112 _tValue
1113 any_cast(any&& x)
1114 {
1115 static_assert(is_any_cast_dest<_tValue>(),
1116 "Invalid cast destination type found.");
1117
1118 if(const auto p = x.template target<remove_reference_t<_tValue>>())
1119 return static_cast<_tValue>(*p);
1120 throw bad_any_cast(x.type(), ystdex::type_id<_tValue>());
1121 }
1123
1124
1125
1127
1128
1138 template<typename _type>
1139 inline _type*
1140 unchecked_any_cast(any* p) ynothrowv
1141 {
1142 yconstraint(p && !p->empty()
1143 && p->unchecked_type() == ystdex::type_id<_type>());
1144 return static_cast<_type*>(p->unchecked_get());
1145 }
1146
1151 template<typename _type>
1152 inline const _type*
1153 unchecked_any_cast(const any* p) ynothrowv
1154 {
1155 yconstraint(p && !p->empty()
1156 && p->unchecked_type() == ystdex::type_id<const _type>());
1157 return static_cast<const _type*>(p->unchecked_get());
1158 }
1160
1167 template<typename _type>
1169 inline _type*
1170 unsafe_any_cast(any* p) ynothrowv
1171 {
1172 yconstraint(p && p->type() == ystdex::type_id<_type>());
1173 return static_cast<_type*>(p->get());
1174 }
1175
1177 template<typename _type>
1178 inline const _type*
1179 unsafe_any_cast(const any* p) ynothrowv
1180 {
1181 yconstraint(p && p->type() == ystdex::type_id<const _type>());
1182 return static_cast<const _type*>(p->get());
1183 }
1185
1186
1187
1188 } // namespace ystdex;
1189
1190 #endif
1191
ystdex::details::any_emplace
Definition: any.h:783
YSLib::Drawing::GBinaryGroup::get
yconstfn _type & get(GBinaryGroup< _type > &val)
取分量。
Definition: YGDIBase.h:242
yassume
#define yassume(_expr)
假定：环境语义。
Definition: cassert.h:99
ystdex::any_ops::pointer_holder::pointer_holder
pointer_holder(pointer value)
取得所有权。
Definition: any.h:205
ystdex::any_ops::value_holder::value_holder
value_holder(_tParam &&arg)
Definition: any.h:141
platform::p
while p p
Definition: YCLib/FileSystem.h:225
YB_NORETURN
#define YB_NORETURN
指定无返回值函数。
Definition: ydef.h:478
YSLib::Drawing::x
The boundary is out of the const Rect SDst SPos x
Definition: YDraw.h:127
ystdex::lref::get
_type & get() const
Definition: ref.hpp:107
ystdex::any_ops::value_holder::operator=
value_holder & operator=(const value_holder &)=default
ystdex::any_ops::get_type
Definition: any.h:251
ystdex::any::unsafe_any_cast
_type * unsafe_any_cast(any *p)
非安全动态泛型转换。
Definition: any.h:1170
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:653
ystdex::any_ops::base_op
base_op
Definition: any.h:247
ystdex::any::any
any(any_ops::use_holder_t, std::unique_ptr< _tHolder > p)
构造：使用指定持有者。
Definition: any.h:860
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:740
ystdex::any::any
any(_type &&x)
Definition: any.h:842
ystdex::any_ops::holder_handler::init
static void init(true_type, any_storage &d, std::unique_ptr< _tHolder > p)
Definition: any.h:568
ystdex::any_ops::pointer_holder::value_type
_type value_type
Definition: any.h:196
ystdex::bad_any_cast::to_ti
lref< const type_info > to_ti
Definition: any.h:640
ystdex::any::any_cast
_tValue any_cast(any &x)
Definition: any.h:1090
ystdex::any_ops::in_place_t
Definition: any.h:83
yconstraint
#define yconstraint(_expr)
约束：接口语义。
Definition: cassert.h:82
ystdex::any_ops::value_handler::copy
static void copy(any_storage &d, const any_storage &s)
Definition: any.h:307
ystdex::any_ops::value_handler::dispose_impl
static void dispose_impl(false_type, any_storage &d)
Definition: any.h:321
ystdex::any_ops::op_code
std::uint32_t op_code
Definition: any.h:244
ystdex::any_ops::pointer_holder::operator=
pointer_holder & operator=(const pointer_holder &)=default
ystdex::any::any
any(any_ops::in_place_t< _type >, _tParams &&...args)
Definition: any.h:849
ystdex::swap
void swap(container_adaptor< _tSeqCon > &x, container_adaptor< _tSeqCon > &y)
Definition: container.hpp:179
ystdex::any::unchecked_type
const type_info & unchecked_type() const
取包含对象的类型。
Definition: any.h:1037
ystdex::any_ops::ref_handler::get_reference
static value_type & get_reference(any_storage &s)
Definition: any.h:500
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: type_traits.hpp:350
ystdex::any_ops::value_holder::clone
value_holder * clone() const override
Definition: any.h:159
ystdex::details::any_base::any_base
any_base(any_ops::with_handler_t< _tHandler >, _tParams &&...args)
Definition: any.h:704
ystdex::any_ops::pointer_holder::pointer
typename holder_pointer::pointer pointer
Definition: any.h:198
ystdex::any_ops::value_handler::get_reference
static const value_type & get_reference(const any_storage &s)
Definition: any.h:375
utility.hpp
实用设施。
ystdex::any_ops::holder
抽象动态泛型持有者接口。
Definition: any.h:97
ystdex::any_ops::value_handler::get_reference
static value_type & get_reference(any_storage &s)
Definition: any.h:370
ystdex::nullptr
const class ystdex::nullptr_t nullptr
ystdex::any_ops::value_handler::get_pointer
static const value_type * get_pointer(const any_storage &s)
Definition: any.h:341
ystdex::boxed_value
包装类类型的值的对象。
Definition: utility.hpp:139
typeinfo.h
ISO C++ 类型信息扩展。
ystdex::any_ops::get_ptr
Definition: any.h:252
ystdex::any::unchecked_get_holder
any_ops::holder * unchecked_get_holder() const
取持有者指针。
Definition: any.h:1027
ystdex::any_ops::clone
Definition: any.h:253
ystdex::any_ops::holder_handler::init
static void init(any_storage &d, std::unique_ptr< _tHolder > p)
Definition: any.h:582
ystdex::any::swap
void swap(any &a)
Definition: any.h:974
ystdex::any_ops::holder_handler::get_holder_pointer
static _tHolder * get_holder_pointer(any_storage &s)
Definition: any.h:551
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:760
ystdex::bad_any_cast::bad_any_cast
bad_any_cast()
Definition: any.h:645
ystdex::details::any_base::target
const _type * target() const
Definition: any.h:753
ystdex::any_ops::pointer_holder::p_held
holder_pointer p_held
Definition: any.h:201
CHRLib::d
_tDst * d
Definition: CharacterProcessing.h:139
ref.hpp
引用包装。
ystdex::bool_constant
integral_constant< bool, _b > bool_constant
bool 常量。
Definition: type_traits.hpp:382
ystdex::standard_layout_storage::access
void * access()
Definition: type_pun.hpp:263
ystdex::any::operator=
any & operator=(any &&a)
转移赋值：使用复制和交换。
Definition: any.h:923
ystdex::any::any
any(_type &&x)
Definition: any.h:832
ystdex::any_ops::value_handler::init
static void init(any_storage &d, _tParams &&...args)
Definition: any.h:414
ystdex::any_ops::holder_handler::value_type
typename _tHolder::value_type value_type
Definition: any.h:546
ystdex::any::unchecked_any_cast
const _type * unchecked_any_cast(const any *p)
Definition: any.h:1153
ystdex::any_ops::end_base_op
Definition: any.h:258
ystdex::any_ops::value_handler
动态泛型对象处理器。
Definition: any.h:295
ystdex::exclude_self_t
enable_if_t<!is_same< _tClass &, decay_t< _tParam > & >::value, _type > exclude_self_t
移除选择类类型的特定重载避免构造模板和复制/转移特殊成员函数冲突。
Definition: type_traits.hpp:708
ystdex::any_ops::holder_handler::init
static void init(false_type, any_storage &d, std::unique_ptr< _tHolder > p)
Definition: any.h:574
ystdex::any::operator=
any & operator=(const any &a)
复制赋值：使用复制和交换。
Definition: any.h:913
ystdex::any::target
_type * target()
取目标指针。
Definition: any.h:988
ystdex::any::unchecked_any_cast
_type * unchecked_any_cast(any *p)
未检查的动态泛型转换。
Definition: any.h:1140
ystdex::any_ops::with_handler_t
Definition: any.h:89
ystdex::any_ops::ref_handler::manage
static void manage(any_storage &d, any_storage &s, op_code op)
Definition: any.h:518
ystdex::lref< const type_info >
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:256
YB_API
#define YB_API
YBase 应用程序编程接口：用于向库文件约定链接。
Definition: ydef.h:566
ystdex::any::any_cast
_type * any_cast(any *p)
动态泛型转换。
Definition: any.h:1072
ystdex::any::type
const type_info & type() const
Definition: any.h:1002
ystdex::bad_any_cast
动态泛型转换失败异常。
Definition: any.h:636
ystdex::any
基于类型擦除的动态泛型对象。
Definition: any.h:823
ystdex::any_ops::holder_handler::get_pointer
static value_type * get_pointer(any_storage &s)
Definition: any.h:557
ystdex::construct
void construct(_tIter i, _tParams &&...args)
使用指定参数在迭代器指定的位置构造对象。
Definition: memory.hpp:189
ystdex::any_ops::value_handler::get_reference_impl
static const value_type & get_reference_impl(true_type, const any_storage &s)
Definition: any.h:403
ystdex::any_ops::any_storage
standard_layout_storage< aligned_storage_t< sizeof(void *), sizeof(void *)>> any_storage
Definition: any.h:264
ystdex::any_ops::get_holder_type
Definition: any.h:255
ystdex::any::unchecked_get
void * unchecked_get() const
取包含对象的指针。
Definition: any.h:1020
ystdex::any_ops::any_manager
void(*)(any_storage &, any_storage &, op_code) any_manager
Definition: any.h:266
ystdex::any_ops::value_handler::dispose
static void dispose(any_storage &d)
Definition: any.h:314
ystdex::any_ops::throw_invalid_construction
void throw_invalid_construction()
Definition: any.cpp:43
ystdex::any_ops::pointer_holder::pointer_holder
pointer_holder(const pointer_holder &h)
Definition: any.h:210
ystdex::any_ops::ref_handler::get_pointer
static value_type * get_pointer(any_storage &s)
Definition: any.h:493
ystdex::any_ops::value_handler::get_reference_impl
static value_type & get_reference_impl(true_type, any_storage &s)
Definition: any.h:398
std
Definition: memory.hpp:1100
ystdex::unwrap_reference_t
_t< unwrap_reference< _type >> unwrap_reference_t
Definition: ref.hpp:176
YB_ATTR
#define YB_ATTR(...)
GNU 风格属性。
Definition: ydef.h:347
ystdex::any_ops::destroy
Definition: any.h:254
ystdex::bad_any_cast::bad_any_cast
bad_any_cast(const type_info &from_, const type_info &to_)
Definition: any.h:650
ystdex::any::any
any(any_ops::with_handler_t< _tHandler > t, _tParams &&...args)
Definition: any.h:887
ystdex::any_ops::holder_handler
动态泛型持有者处理器。
Definition: any.h:540
ystdex::any_ops::construct
any_manager construct(any_storage &storage, _tParams &&...args)
使用指定处理器初始化存储。
Definition: any.h:274
ystdex::any::any_cast
_tValue any_cast(any &&x)
Definition: any.h:1113
ystdex::any_ops::value_handler::dispose_impl
static void dispose_impl(true_type, any_storage &d)
Definition: any.h:326
ystdex::details::any_emplace::emplace
void emplace(_tParams &&...args)
Definition: any.h:787
ystdex::any_ops::value_handler::get_pointer
static value_type * get_pointer(any_storage &s)
Definition: any.h:336
ystdex::any_ops::value_handler::init_impl
static void init_impl(false_type, any_storage &d, _tParams &&...args)
Definition: any.h:422
ystdex::any_ops::pointer_holder
指针类型动态泛型持有者。
Definition: any.h:189
ystdex
特性测试宏。
Definition: ydef.h:796
ystdex::cpp2014::decay_t
typename decay< _type >::type decay_t
Definition: type_traits.hpp:347
ystdex::any_ops::value_handler::get_pointer_impl
static value_type * get_pointer_impl(false_type, any_storage &s)
Definition: any.h:348
ystdex::any_ops::value_holder::type
const type_info & type() const override
Definition: any.h:173
ystdex::any::any
any(any_ops::use_holder_t, any_ops::in_place_t< _tHolder >, _tParams &&...args)
Definition: any.h:872
ystdex::any::unsafe_any_cast
const _type * unsafe_any_cast(const any *p)
Definition: any.h:1179
ystdex::any_ops::get_holder_ptr
Definition: any.h:256
ystdex::any_ops::value_handler< _tHolder >::local_storage
bool_constant< and_< is_nothrow_move_constructible< _tHolder >, is_aligned_storable< any_storage, _tHolder >>::value > local_storage
Definition: any.h:301
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
ystdex::any::swap
void swap(any &x, any &y)
交换对象。
Definition: any.h:1053
ystdex::any_ops::value_handler::get_pointer_impl
static const value_type * get_pointer_impl(false_type, const any_storage &s)
Definition: any.h:353
ystdex::path_category::empty
ystdex::any_ops::value_handler::get_pointer_impl
static value_type * get_pointer_impl(true_type, any_storage &s)
Definition: any.h:358
ystdex::any_ops::value_handler::try_init
static void try_init(false_type, _tParams &&...)
Definition: any.h:466
ystdex::any::any
any(_type &&x, any_ops::use_holder_t)
Definition: any.h:880
ynoexcept
#define ynoexcept(...)
YSLib 无异常抛出保证：指定特定的异常规范。
Definition: ydef.h:720
ystdex::any_ops::no_op
Definition: any.h:250
ystdex::details::any_emplace::emplace_with_handler
void emplace_with_handler(_tParams &&...args)
Definition: any.h:802
ystdex::type_id
const type_info & type_id()
Definition: typeinfo.h:149
ystdex::any_ops::value_handler::get_pointer_impl
static const value_type * get_pointer_impl(true_type, const any_storage &s)
Definition: any.h:363
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:167
ystdex::any_ops::value_holder::value_type
_type value_type
Definition: any.h:134
ystdex::standard_layout_storage
任意标准布局类型存储。
Definition: type_pun.hpp:227
ystdex::details::any_emplace::emplace
void emplace(any_ops::use_holder_t, _tParams &&...args)
Definition: any.h:794
ystdex::any::any
any(any_ops::use_holder_t, _tHolder &&h)
Definition: any.h:866
ystdex::any_ops::pointer_holder::holder_pointer
_tPointer holder_pointer
Definition: any.h:197
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:969
ystdex::boxed_value::value
_type value
Definition: utility.hpp:142
ystdex::is_cv
判断指定类型是否为 const 或 volatile 类型。
Definition: type_traits.hpp:842
ystdex::any_ops::use_holder
const struct ystdex::any_ops::use_holder_t use_holder
ystdex::is_aligned_storable
判断是否可对齐存储。
Definition: type_pun.hpp:72
ystdex::any_ops::use_holder_t
使用持有者标记。
Definition: any.h:285
ystdex::any_ops::value_handler::manage
static void manage(any_storage &d, any_storage &s, op_code op)
Definition: any.h:437
ystdex::or_
Definition: type_traits.hpp:412
ystdex::details::any_base::unchecked_access
_type unchecked_access(any_ops::any_storage &t, any_ops::op_code op) const
Definition: any.h:774
YB_ATTR_returns_nonnull
#define YB_ATTR_returns_nonnull
指示返回非空属性。
Definition: ydef.h:390
ystdex::any_ops::ref_handler
动态泛型引用处理器。
Definition: any.h:485
ystdex::any_ops::value_holder::value_holder
value_holder()=default
CHRLib::args
_tParams && args
Definition: CharacterProcessing.h:538
ystdex::any_ops::ref_handler::value_type
_type value_type
Definition: any.h:488
ystdex::any_ops::pointer_holder::clone
pointer_holder * clone() const override
Definition: any.h:222
ystdex::any::any
any(any &&a)
Definition: any.h:892
ystdex::any_ops::value_holder
值类型动态泛型持有者。
Definition: any.h:127
ystdex::and_
逻辑操作元函数。
Definition: type_traits.hpp:394
ystdex::any::get_holder
any_ops::holder * get_holder() const
Definition: any.h:942
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:510
ystdex::is_reference_wrapper
判断模板参数指定的类型是否。
Definition: ref.hpp:150
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
ystdex::any::operator=
any & operator=(_type &&x)
Definition: any.h:903
ystdex::cloneable
可动态复制的抽象基类。
Definition: base.h:117
ystdex::any_ops::value_handler< _tHolder >::value_type
_tHolder value_type
Definition: any.h:300
ystdex::any_ops::holder_handler::manage
static void manage(any_storage &d, any_storage &s, op_code op)
Definition: any.h:591
ystdex::details::any_base::get_storage
any_ops::any_storage & get_storage() const
Definition: any.h:736
ystdex::details::any_base
Definition: any.h:695
ystdex::any_ops::pointer_holder::type
const type_info & type() const override
Definition: any.h:236
ystdex::any::target
const _type * target() const
Definition: any.h:994
ystdex::any_ops::value_handler::get_reference_impl
static const value_type & get_reference_impl(false_type, const any_storage &s)
Definition: any.h:390
ystdex::any_ops::value_handler::get_reference_impl
static value_type & get_reference_impl(false_type, any_storage &s)
Definition: any.h:382