Struct FieldInfo
Contains the size and offset of a field within a struct
struct FieldInfo
;
Example
size & layout checks for C++ structs / objects
foreach (Type; TypesWithLayout)
{
foreach (idx, field; Type .init .tupleof)
{
auto object = Type .init;
auto field_info = cppFieldInfo(object,
Type .tupleof[idx] .stringof .toStringz);
assert(typeof(field) .sizeof == field_info .size,
format("Field '%s' of '%s' size mismatch: %s (D) != %s (C++)",
Type .tupleof[idx] .stringof, Type .stringof,
typeof(field) .sizeof, field_info .size));
assert(Type .tupleof[idx] .offsetof == field_info .offset,
format("Field '%s' of '%s' offset mismatch: %s (D) != %s (C++)",
Type .tupleof[idx] .stringof, Type .stringof,
Type .tupleof[idx] .offsetof, field_info .offset));
}
}