KhronosGroup / KhronosGroup/OpenXR-Hpp

Support for C++20 Designated initializers

Open
#27 4 comments 2 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
C++
Stars
50
Forks
23
PR merge metrics
No merged PRs in 30d

Description

I would like to discuss adding support for designated initializers. It would allow to write code like this:
```
session.endFrame(xr::FrameEndInfo{
.displayTime = frame_state.predictedDisplayTime,
.environmentBlendMode = xr::EnvironmentBlendMode::Opaque,
.layerCount = static_cast(layers_pointers.size()),
.layers = layers_pointers.data() });
```
I think it's an important feature as it makes code much easier to understand.

It only works on aggregates, so we would need to make some changes to the way structs are generated. The two importants one are:
* Remove the inheritance in the structs (for example remove `impl::InputStructBase`)
* Option to remove the constructor using a macro `OPENXR_HPP_NO_CONSTRUCTOR`

I had a working implementation [in my fork](https://github.com/matthieucoquet/OpenXR-Hpp/commit/d47c7c9ff14b35322508ede5ba08750c36807f30), but they were too much change in `split-headers`. I would like to implement it again, but I would like to have support of this directly here.

Would you agree to have changes to the structs in order to support designated initializers?
Can a PR that removes all the inheritances in the structs be accepted? (It would still have proper default value of course)

To conclude, here is what a struct looked like in my fork (before `split-headers`):
```
struct FrameEndInfo {
#ifndef OPENXR_HPP_NO_CONSTRUCTOR
FrameEndInfo(const Time &displayTime_ = {},
const EnvironmentBlendMode &environmentBlendMode_ = {},
uint32_t layerCount_ = {},
const CompositionLayerBaseHeader *const *layers_ = nullptr)
: displayTime{displayTime_}, environmentBlendMode{environmentBlendMode_},
layerCount{layerCount_}, layers{layers_} {}
#endif
operator const XrFrameEndInfo &() const {
return *reinterpret_cast(this);
}
operator XrFrameEndInfo &() {
return *reinterpret_cast(this);
}

StructureType type = StructureType::FrameEndInfo;
const void *XR_MAY_ALIAS next = nullptr;
Time displayTime = {};
EnvironmentBlendMode environmentBlendMode = {};
uint32_t layerCount = {};
const CompositionLayerBaseHeader *const *layers = nullptr;
};
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing the generated structs in split-headers and comparing them with the working implementation linked from the issue. Determine whether designated initializers can be supported while preserving default values, conversions, and the optional constructor; done requires an agreed design and an accepted implementation scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
ar-vr-xr
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.