XRTraits C++ OpenXR Utilities
twocall-in-place-sized-and-initialized.cpp

This example shows a mostly-equivalent scenario to twocall-size-hint-and-initialized.cpp, but instead uses the doTwoCallInPlace() function which avoids exceptions and returns the XrResult from the final wrapped call. See that other example for more detail, including explanations of the xrtraits::Initialized usage.

Because views is not empty, that will be used as a size hint, so if (as expected) xrLocateViews output fits in that size, only a single call to the wrapped function is needed.

// Copyright 2019, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
#include <iostream>
int main()
{
uint32_t numViews = 2; // Previously initialized as required.
XrSpace local; // Previously initialized
XrSession session; // Previously initialized
XrTime frameTime; // Previously initialized
Initialized<XrViewState> viewState; // Output
Initialized<XrViewLocateInfo> viewLocateInfo{frameTime, local}; // Input
auto views = make_zeroed_vector<XrView>(numViews);
XrResult result = doTwoCallInPlace(views, xrLocateViews, session,
&viewLocateInfo, &viewState);
return 0;
}