17 #include <openxr/openxr.h>    21 #include <type_traits>    41     static_assert(traits::has_xr_type_tag_v<T>,
    42                   "Can only call initXrType to initialize a type with a "    43                   "known OpenXR type tag");
    46         "Doesn't make sense to pass a reference to const to initXrType()");
    47     std::memset(storage, 0, 
sizeof(T));
    48     storage->type = traits::xr_type_tag_v<T>;
    57 template <
typename T> 
inline T* 
initXrType(
void* storage)
    60     return initXrType(reinterpret_cast<T*>(storage));
    74         "Doesn't make sense to pass a reference to const to initXrType()");
    78 #ifndef XRTRAITS_DOXYGEN    82     template <
typename T, 
typename = 
void> 
struct ConditionalInitXrType
    84         static void apply(T&) {}
    87     struct ConditionalInitXrType<
    88         T, std::enable_if_t<traits::has_xr_type_tag_v<T>>>
    90         static void apply(T& storage) { 
initXrType(&storage); }
    94 #endif // !XRTRAITS_DOXYGEN   105     detail::ConditionalInitXrType<T>::apply(ret);
   116     return std::vector<T>{n, make_zeroed<T>()};
   119 #ifndef XRTRAITS_DOXYGEN   122     template <
typename T>
   123     struct is_chainable_struct_oracle : std::false_type
   126 #ifdef XRTRAITS_HAVE_DYNAMIC_VERIFIED   127     template <
typename U>
   128     struct is_chainable_struct_oracle<DynamicVerified<U>> : std::true_type
   131 #endif // XRTRAITS_HAVE_DYNAMIC_VERIFIED   133     template <
typename U>
   134     struct is_chainable_struct_oracle<Initialized<U>> : std::true_type
   137     template <
typename T>
   138     constexpr 
bool is_chainable_struct_v = is_chainable_struct_oracle<
   139         std::remove_cv_t<std::remove_reference_t<T>>>::value;
   141 #endif // !XRTRAITS_DOXYGEN   147 #pragma GCC diagnostic push   148 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"   163     static_assert(traits::has_xr_type_tag_v<T>,
   164                   "Can only use Initialized<T> with a type with a known "   166     static_assert(!is_pointer_v<T>,
   167                   "Can't use Initialized<T> with a pointer type - just use "   168                   "the bare type, we are stack allocating.");
   169     static_assert(!is_reference_v<T>,
   170                   "Can't use Initialized<T> with a reference type.");
   171     static_assert(!is_const_v<T>,
   172                   "Can't use Initialized<T> with a const type - doesn't "   182     constexpr 
xr_type* 
get() noexcept { 
return this; }
   195     void type() 
const = 
delete;
   205     void next() 
const = 
delete;
   212         static_cast<T*
>(
this)->type = traits::xr_type_tag_v<T>;
   215 #ifdef XRTRAITS_HAVE_DYNAMIC_VERIFIED   224     template <
typename U, 
typename... Args>
   226         DynamicVerified<U> nextStruct,
   227         Args... a) noexcept(noexcept(nextStruct.get()))
   228         : T({traits::xr_type_tag_v<T>, nextStruct.get(),
   229              std::forward<Args>(a)...})
   231 #endif // XRTRAITS_HAVE_DYNAMIC_VERIFIED   241     template <
typename U, 
typename... Args>
   244         : T({traits::xr_type_tag_v<T>, nextStruct.get(),
   245              std::forward<Args>(a)...})
   249                 !
is_same_v<std::remove_cv_t<T>, std::remove_cv_t<U>>,
   250             "Can't copy Initialized<T> structures.");
   261     template <
typename U, 
typename... Args>
   264         : T({traits::xr_type_tag_v<T>, nextStruct.get(),
   265              std::forward<Args>(a)...})
   268             !
is_same_v<std::remove_cv_t<T>, std::remove_cv_t<U>>,
   269             "Can't copy Initialized<T> "   278         typename A1, 
typename... Args,
   279         typename = std::enable_if_t<!detail::is_chainable_struct_v<A1>>>
   281         : T({traits::xr_type_tag_v<T>, 
nullptr, std::forward<A1>(a1),
   282              std::forward<Args>(a)...})
   300 #ifdef XRTRAITS_HAVE_DYNAMIC_VERIFIED   302     using verified_type = DynamicVerified<xr_type>;
   305     using const_verified_type = DynamicVerified<std::add_const_t<xr_type>>;
   312     constexpr verified_type asVerified() { 
return verified_type{*
get()}; }
   319     constexpr const_verified_type asVerified()
 const   321         return const_verified_type{*
get()};
   329     constexpr const_verified_type asVerifiedConst()
 const   339     constexpr 
operator verified_type() { 
return asVerified(); }
   346     constexpr 
operator const_verified_type()
 const { 
return asVerified(); }
   347 #endif // XRTRAITS_HAVE_DYNAMIC_VERIFIED   351 #pragma GCC diagnostic pop Main namespace for these C++ OpenXR utilities. 
Definition: GetChained.h:26
T xr_type
The OpenXR structure type. 
Definition: InitXrType.h:176
C++ type traits related to OpenXR, and some other compile-time functionality. 
constexpr bool is_same_v
Variable template wrapping std::is_same<T, U>::value. 
Definition: Common.h:34
T * initXrType(T *storage)
Definition: InitXrType.h:39
constexpr Initialized(Initialized< U > const &nextStruct, Args... a) noexcept
Definition: InitXrType.h:242
constexpr Initialized(A1 &&a1, Args... a) noexcept
Definition: InitXrType.h:280
Definition: InitXrType.h:161
T make_zeroed()
Definition: InitXrType.h:102
std::vector< T > make_zeroed_vector(size_t n)
Definition: InitXrType.h:114
constexpr Initialized(Initialized< U > &nextStruct, Args... a) noexcept
Definition: InitXrType.h:262
std::add_const_t< T > const_xr_type
The OpenXR structure type (const). 
Definition: InitXrType.h:179
Header providing type-enforced verification of OpenXR "tagged types". 
constexpr Initialized() noexcept
Default constructor - initializes OpenXR struct's type member. 
Definition: InitXrType.h:208