I would like to be able to have the following construct that exists in Delphi to also work in c++
First the Delphi code:
type
TSlice = record
private
function GetData4: UINT32; inline;
procedure SetData4(Index: 0..15; Value: UINT32); inline;
public
Data8: array[0..7] of UINT64;
property Data4[index: 0..15]: UINT32 read GetData4 write SetData4;
end;
Now the c++ code that I have and works:
struct TSlice {
UINT64 Data8[8];
__device__ __forceinline__ UINT32 * Data4() { return reinterpret_cast<UINT32*>(Data8); }
}
However, I still have to write
for (auto i = 0; i < 3; i++) {
Slice->Data4()[lane * 4] = SliverPart;
Slice->Data4()[lane * 4 + 1] = SliverPart;
}
I would really like to drop the ()
here: Slice->Data2[lane * 4]
Declaring Data4
as UINT32 *const Data4 = (UINT32 *)&Data8;
In the struct does not help, because that gains me an extra 8 bytes, which is not what I want.
I want the translation to be seamless.
How can I do this?
I was thinking of overloading the []
operator, but that would necessitate making Data4
a sub struct and even then I'm not sure it would work if I want to have everything to work inline (i.e. without any runtime overhead).
Using a union works, but the amount of dots that I need to type in the client code is out of this world (classname.unionname.datamember.arrayname[index]
)