2 ms·
> Why would you still manually traverse a linked list? Oh right because C doesn't have parametric polymorphism (genericity) so you can't abstract out the traver
by jstimpfle 7y ago
> Why would you still manually traverse a linked list? Oh right because C doesn't have parametric polymorphism (genericity) so you can't abstract out the traversal in a standard library.
It's pretty easy to make something like this work:
list_insert(&itemList, struct Item, &item, &compare_item);
Which would be just a thin macro, for example defined like this
#define list_insert(list, type, item, compare) \
__list_insert((list), \
sizeof (type), __alignof(type), \
(item), (compare))
You could further "improve" to even allow
DEFINE_LIST_FUNCS(itemList, struct ItemList, compare_items);
itemList_insert(&itemList, &item);
It's not the end of the world. The reason C programmers usually don't make or use such "libraries" is that these are pretty easy to craft on the spot, and there are just a billion way of making it work. Allocation strategy and intrusively vs extrusively linked are two example considerations. I for one prefer to think about the best way to organize my code and data, so I'm not interested in such a library.