KhronosGroup / Vulkan-Hpp

Open-Source Vulkan C++ API
Apache License 2.0
3.08k stars 304 forks source link

ArrayProxy with designated initializers #1909

Open barcharcraz opened 2 months ago

barcharcraz commented 2 months ago

It seems like it should be possible for vulkan-hpp to generate structure types that look approximately like:

struct WhateverInfo {
  ...
   union {
     struct {
        uint32_t whateverThingsCount;
        whateverThing* pWhateverThings;
     };
     ArrayProxyNoTemporaries<whateverThing> whateverThings;
   };
};

or even just an option to generate ArrayProxy data members instead of the count and pointer members.

Is there interest in this?

Note: this relies on the commonly implemented extension where reading non-active union members is allowed. This isn't that relevant because you're using this extension across translation units (one of which is likely C), and vulkan-hpp is already fudging things in this area.

Edit: actually, reading the non-active union member is defined behavior, ArrayProxy and the anonymous struct have a common-initial-sequence. And casting this to the "normal" definition and reading from it is also (probably?) defined behavior because the two types should be layout-compatible (although the rules for layout compatibility between a struct and a union like this don't seem that well specified).