4 ms·
One can implement linked lists as you describe in a C++ fashion using multiple inheritance. The LLVM project has many examples of this using the ilist_node clas
by aleden 11y ago
One can implement linked lists as you describe in a C++ fashion using multiple inheritance. The LLVM project has many examples of this using the ilist_node class [1], e.g. [2].
Between using preprocessor directives in C and multiple inheritance in C++ (comes with associated complexity in the resulting client code), I'd always pick the latter.
[1] https://github.com/llvm-mirror/llvm/blob/release_37/include/llvm/ADT/ilist_node.h#L43 https://github.com/llvm-mirror/llvm/blob/release_37/include/...
[2] https://github.com/llvm-mirror/llvm/blob/release_37/include/llvm/IR/BasicBlock.h#L66 https://github.com/llvm-mirror/llvm/blob/release_37/include/...
- fanf2 11y agoHow do you put an object on multiple different lists with this technique? E.g. in FreeBSD an mbuf can be on two lists at once: http://svnweb.freebsd.org/base/head/sys/sys/mbuf.h?revision=293439&view=markup#l178 http://svnweb.freebsd.org/base/head/sys/sys/mbuf.h?revision=...