15 #if defined(XRTRAITS_HAVE_DYNAMIC_VERIFIED) && defined(XRTRAITS_HAVE_OPTIONAL)    21 #define XRTRAITS_HAVE_POLYMORPHIC_SPAN    41 template <
typename T> 
class PolymorphicSpan;
    48 make_polymorphic_span(T* pointer, std::ptrdiff_t size,
    49                       const char* paramName = 
nullptr,
    50                       XrResult errorCode = exceptions::DEFAULT_TYPE_ERROR_CODE);
    52 template <
typename T> 
class PolymorphicSpan
    56     using size_type = std::ptrdiff_t;
    61     constexpr PolymorphicSpan(T* pointer, size_type sz,
    62                               const char* paramName = 
nullptr,
    63                               optional<XrResult> 
const& errorCode = nullopt)
    64         : ptr_(pointer), size_(sz), paramName_(paramName),
    69     constexpr size_type size()
 const { 
return size_; }
    72     constexpr T* data()
 const { 
return ptr_; }
    76     constexpr DynamicVerifiedSpan<U>
    77     cast(
const char* paramName = 
nullptr,
    78          optional<XrResult> 
const& errorCode = nullopt)
 const    81             traits::same_constness<T, U>,
    82             "Can't change constness with PolymorphicSpan<T>::cast<U>");
    83         static_assert(traits::has_xr_type_tag_v<U>,
    84                       "Can only cast with PolymorphicSpan<T>::cast<U> "    85                       "to a type with a known tag");
    86         auto result = errorCode.value_or(
    87             errorCode_.value_or(exceptions::DEFAULT_TYPE_ERROR_CODE));
    88         auto param = (paramName != 
nullptr) ? paramName : paramName_;
    89         if (ptr_ == 
nullptr) {
    90             throw exceptions::type_error(param, 
nullptr,
    91                                          traits::xr_type_tag_v<U>,
    95         return {
reinterpret_cast<U*
>(ptr_), size_, paramName, result};
   101     const char* paramName_;
   102     optional<XrResult> errorCode_;
   111 template <
typename TargetType, 
typename SourceType>
   113 required_verified_span_cast(PolymorphicSpan<SourceType> 
const& source,
   114                             const char* paramName = 
nullptr,
   115                             optional<XrResult> 
const& errorCode = nullopt);
   116 template <
typename T>
   118 make_polymorphic_span(T* pointer, std::ptrdiff_t size, 
const char* paramName,
   121     return {pointer, size, paramName, errorCode};
   124 template <
typename TargetType, 
typename SourceType>
   126 required_verified_span_cast(PolymorphicSpan<SourceType> 
const& source,
   127                             const char* paramName,
   128                             optional<XrResult> 
const& errorCode)
   131         traits::same_constness<SourceType, TargetType>,
   132         "Can't change constness with required_verified_span_cast");
   133     static_assert(traits::has_xr_type_tag_v<TargetType>,
   134                   "Can only cast with required_verified_span_cast "   135                   "to a type with a known tag");
   136     return source.template cast<TargetType>(paramName, errorCode);
   140 #endif // defined(XRTRAITS_HAVE_DYNAMIC_VERIFIED) && defined(XRTRAITS_HAVE_OPTIONAL) Main namespace for these C++ OpenXR utilities. 
Definition: GetChained.h:26
 
#define XRTRAITS_NODISCARD
Compatibility wrapper for [[nodiscard]] 
Definition: Attributes.h:24
 
Header with common utilities used by multiple headers. 
 
Header providing type-enforced verification of OpenXR "tagged types".