12 #include "../Common.h" 14 #ifdef XRTRAITS_HAVE_CONSTEXPR_IF 17 #include "../Attributes.h" 18 #include "../exceptions/CastExceptions.h" 52 template <
typename TargetType,
typename SourceType>
55 using std::conditional_t;
56 using std::remove_reference_t;
58 conditional_t<is_pointer_v<remove_reference_t<SourceType>>,
59 remove_reference_t<SourceType>, SourceType>;
60 using Tgt = TargetType;
65 traits::is_xr_tagged_type_v<Src>,
66 "Can only use xr_tagged_dynamic_cast to cast from " 67 "a pointer/reference to (possibly const) XR tagged " 68 "types. If you really want to cast from something like a " 69 "void *, you are looking for xr_tagged_risky_cast.");
72 traits::is_xr_tagged_type_v<Tgt>,
73 "Can only use xr_tagged_dynamic_cast to cast to a " 74 "pointer/reference to a (possibly const) XR tagged " 85 traits::has_xr_type_tag_v<Tgt>,
86 "Can only use xr_tagged_dynamic_cast to cast to a " 87 "pointer/reference to a concrete XR tagged type " 88 "with a known, defined type tag value (XrStructureType " 91 static_assert(detail::points_or_refers_to_const_v<Src>
92 ? detail::points_or_refers_to_const_v<Tgt>
94 "Cannot remove const qualification through " 95 "xr_tagged_dynamic_cast");
96 #ifndef XRTRAITS_USE_EXCEPTIONS 97 static_assert(is_pointer_v<Tgt>,
98 "Casts to references require the availability of " 99 "xrtraits exceptions.");
100 #endif // !XRTRAITS_USE_EXCEPTIONS 103 "xr_tagged_dynamic_cast";
104 constexpr
bool is_target_pointer = is_pointer_v<Tgt>;
106 if constexpr (is_pointer_v<Src>) {
109 if (source ==
nullptr) {
110 if constexpr (is_target_pointer) {
116 #ifdef XRTRAITS_USE_EXCEPTIONS 118 traits::xr_type_tag_v<Tgt>,
nullptr,
120 #endif // XRTRAITS_USE_EXCEPTIONS 125 if (traits::xr_type_tag_v<Tgt> == detail::get_type(source)) {
128 return detail::perform_dereferencing_reinterpret_cast<
133 if constexpr (is_target_pointer) {
139 #ifdef XRTRAITS_USE_EXCEPTIONS 141 traits::xr_type_tag_v<Tgt>,
142 detail::get_type(source), castType);
143 #endif // XRTRAITS_USE_EXCEPTIONS 151 #endif // XRTRAITS_HAVE_CONSTEXPR_IF Main namespace for these C++ OpenXR utilities.
Definition: GetChained.h:26
#define XRTRAITS_MAYBE_UNUSED
Compatibility wrapper for [[maybe_unused]]
Definition: Attributes.h:26
Definition: CastExceptions.h:38
TargetType xr_tagged_dynamic_cast(SourceType &&source)
Definition: TaggedDynamicCast.h:53
Header shared between the two type-safe cast headers.