XRTraits C++ OpenXR Utilities
Functions
xrtraits::casts Namespace Reference

Casts for OpenXR tagged types, as well as utilities for traversing a next chain. More...

Functions

template<typename TargetType , typename SourceType >
TargetType xr_get_chained_struct (SourceType *src)
 
template<typename T >
T * xr_get_chained_struct (T *src)
 
template<typename TargetType , typename SourceType >
TargetType xr_tagged_dynamic_cast (SourceType &&source)
 
template<typename TargetType , typename SourceType >
TargetType xr_tagged_risky_cast (SourceType source)
 

Detailed Description

Casts for OpenXR tagged types, as well as utilities for traversing a next chain.

The non-chained "cast-like" functions:

In both xr_tagged_dynamic_cast() and xr_tagged_risky_cast(), if the target type parameter you supply is a pointer type, a null pointer input or mismatch of the type member with your target type will result in the cast returning nullptr if your target is a pointer type, or throwing xrtraits::exceptions::bad_tagged_cast if your target is a reference type. Choose whether to request a pointer or reference type as target based on your confidence that the input is the right type; remember that exceptions are for exceptional cases. This behavior intentionally resembles the standard dynamic_cast.

If these are used wrong, there are static assertions that will try to provide a helpful error message.