XRTraits C++ OpenXR Utilities
Functions
Two-Call Idiom Wrappers

Functions simplifying calls that return a variable-length buffer/array. More...

Functions

template<typename T , typename F , typename... Args>
std::vector< T > xrtraits::doTwoCall (F &&wrappedCall, Args &&... a)
 
template<typename T , typename F , typename... Args>
std::vector< T > xrtraits::doTwoCallWithSizeHint (uint32_t sizeHint, F &&wrappedCall, Args &&... a)
 
template<typename T , typename F , typename... Args>
XrResult xrtraits::doTwoCallInPlace (std::vector< T > &container, F &&wrappedCall, Args &&... a)
 

Detailed Description

Functions simplifying calls that return a variable-length buffer/array.

Some of these functions may take a leading argument, such as a size hint or a container to populate. However, after that possible argument, the rest are standardized:

Function Documentation

◆ doTwoCall()

template<typename T , typename F , typename... Args>
std::vector<T> xrtraits::doTwoCall ( F &&  wrappedCall,
Args &&...  a 
)
inline

#include <xrtraits/TwoCall.h>

Perform the two call idiom, returning a vector.

Template Parameters
TThe type of the buffer element you expect
Parameters
wrappedCallA function or lambda that takes the capacityInput, countOutput, and array parameters as its only or last parameters.
aAny additional arguments passed to this call will be forwarded to the call before the capacityInput, countOutput, and array parameters.
Exceptions
iffinal call does not return XR_SUCCESS

Requires XR_USE_EXCEPTIONS.

Examples:
twocall-function-and-one-arg.cpp, and twocall-just-function.cpp.

References xrtraits::make_zeroed_vector(), and xrtraits::exceptions::throwIfNotUnqualifiedSuccess().

◆ doTwoCallInPlace()

template<typename T , typename F , typename... Args>
XrResult xrtraits::doTwoCallInPlace ( std::vector< T > &  container,
F &&  wrappedCall,
Args &&...  a 
)
inline

#include <xrtraits/TwoCall.h>

Perform the two call idiom, returning XrResult, to populate an existing container, whose size may hint at expected count.

Parameters
containerThe container to fill. If it is not empty, the buffer size will be used as a size hint: if sufficient, only one call to the wrappedCall will be made.
wrappedCallA function or lambda that takes the capacityInput, countOutput, and array parameters as its only or last parameters.
aAny additional arguments passed to this call will be forwarded to the call before the capacityInput, countOutput, and array parameters.

Does not require XR_USE_EXCEPTIONS.

Examples:
twocall-in-place-just-function.cpp, and twocall-in-place-sized-and-initialized.cpp.

◆ doTwoCallWithSizeHint()

template<typename T , typename F , typename... Args>
std::vector<T> xrtraits::doTwoCallWithSizeHint ( uint32_t  sizeHint,
F &&  wrappedCall,
Args &&...  a 
)
inline

#include <xrtraits/TwoCall.h>

Perform the two call idiom, returning a vector, when we already have a hint about the capacity.

Template Parameters
TThe type of the buffer element you expect
Parameters
sizeHintThe buffer size to attempt: if sufficient, only one call to the wrappedCall will be made.
wrappedCallA function or lambda that takes the capacityInput, countOutput, and array parameters as its only or last parameters.
aAny additional arguments passed to this call will be forwarded to the call before the capacityInput, countOutput, and array parameters.
Exceptions
iffinal call does not return XR_SUCCESS

Requires XR_USE_EXCEPTIONS.

Examples:
twocall-size-hint-and-initialized.cpp.

References xrtraits::make_zeroed_vector(), and xrtraits::exceptions::throwIfNotUnqualifiedSuccess().