14 #include "../Common.h" 16 #ifdef XRTRAITS_HAVE_CONSTEXPR_IF 24 #define XRTRAITS_HAVE_CASTS 27 #include "../Common.h" 28 #include "../traits/APITraits.h" 31 #include <openxr/openxr.h> 34 #include <type_traits> 39 #ifndef XRTRAITS_DOXYGEN 42 using ::std::add_pointer_t;
43 using ::std::enable_if_t;
44 using ::std::integral_constant;
45 using ::std::is_const;
46 using ::std::is_pointer;
47 using ::std::remove_const_t;
48 using ::std::remove_pointer_t;
49 using namespace ::xrtraits::traits::detail;
55 constexpr
bool points_or_refers_to_const_v =
56 is_const_v<detail::remove_reference_pointer_t<T>>;
62 constexpr
bool points_to_const_v =
63 is_const_v<remove_pointer_t<T>>;
68 constexpr
bool is_pointer_to_const_v =
69 is_pointer_v<T>&& points_to_const_v<T>;
75 is_pointer_to_nonconst_v = is_pointer_v<T> &&
76 (!points_to_const_v<T>);
81 template <
typename T,
typename U>
82 constexpr
bool pointed_to_constness_is_equal_v =
83 points_to_const_v<T> == points_to_const_v<U>;
87 template <
typename TargetType,
typename SourceType>
89 perform_pointer_reinterpret_cast(SourceType* source)
91 using Source = add_pointer_t<SourceType>;
92 static_assert(!(is_pointer_to_const_v<
93 add_pointer_t<SourceType>> &&
94 is_pointer_to_nonconst_v<TargetType>),
95 "Can't remove constness with " 96 "perform_pointer_reinterpret_cast");
97 if constexpr (pointed_to_constness_is_equal_v<
98 SourceType, TargetType>) {
99 return reinterpret_cast<TargetType
>(
104 is_pointer_to_nonconst_v<Source> &&
105 is_pointer_to_const_v<TargetType>,
106 "If constness doesn't match, must have " 107 "ptr-to-non-const source and ptr-to-const " 109 using TargetNonConst =
110 add_pointer_t<remove_const_t<
111 remove_pointer_t<TargetType>>>;
113 reinterpret_cast<TargetNonConst
>(
116 return const_cast<TargetType
>(t);
120 template <
typename T>
inline auto get_pointer(T&& obj)
129 template <
typename TargetType,
typename SourceType>
131 perform_dereferencing_reinterpret_cast(SourceType&& source)
133 constexpr
bool isTargetPtr = is_pointer_v<TargetType>;
135 auto sourcePtr = get_pointer(source);
136 if constexpr (isTargetPtr) {
137 return perform_pointer_reinterpret_cast<
138 TargetType>(sourcePtr);
141 return *perform_pointer_reinterpret_cast<
142 add_pointer_t<TargetType>>(sourcePtr);
153 template <
typename T>
154 constexpr XrStructureType
155 get_type(T&& o, std::enable_if_t<traits::is_xr_tagged_type_v<T>,
160 traits::is_xr_tagged_type_v<T>,
161 "Can only use get_type() on a pointer/reference to " 162 "a (possibly const) XR tagged type.");
164 std::remove_reference_t<T>>) {
172 #endif // !XRTRAITS_DOXYGEN 177 #endif // XRTRAITS_HAVE_CONSTEXPR_IF Main namespace for these C++ OpenXR utilities.
Definition: GetChained.h:26
constexpr bool is_pointer_v
Variable template wrapping std::is_pointer<T>::value.
Definition: Common.h:23