On Wednesday, 20 September 2023 at 17:14:41 UTC, Dejan Lekic
wrote:
[...]
NK_CONTAINER_OF should probably be translated to:
`cast(T*)((cast(void*)ptr - __traits(getMember, T,
member).offsetof))`
PS. I did not invent this. My original idea was far worse than
this. - It was suggested on IRC by a much cleverer D programmer
than myself - Herringway@IRC
Thanks! I translated it to this originally after looking at the
links you've provided:
```D
auto nk_container_of(P, T)(P ptr, T type, size_t member_offsetof)
{
return cast(T*)(cast(void*)(cast(char*)(1 ? (ptr) : ptr -
member_offsetof)));
}
```
`cast(T*)((cast(void*)ptr - __traits(getMember, T,
member).offsetof))`
Now, how should I wrap it like a macro? Template mixin? I'm not
that familiar with D meta programming... I shall skim through the
`D templates tutorial` for hints.