4 ms·
You can totally make array iteration generic, just pass the element size. Not saying it is necessarily a good idea. I agree that there are cases where the "the
by jstimpfle 5y ago
You can totally make array iteration generic, just pass the element size. Not saying it is necessarily a good idea.
I agree that there are cases where the "there should be a single central piece of code" argument is not a strong one, because the generic code is so simple that it should be inlined into the usage code. Arrays iteration is one example - but note that for example sorting code is, while the sorting algorithm might be generic, more than just generic array iteration.
Doubly linked lists already profit from shared code in some ways, and definitely I'd find it a bad idea to replicate for example tree mutation code (RB tree or similar) for each node type. Embedding the header structure and keeping the links just between these embedded headers, to be able to reuse a common (compiled) piece of code is a very good idea here IMO.