For example, Linux's list.h has an intrusive list that is far better than the abysmal std::list from the STL.
They all either take ownership of your data, or point at your data unidirectionally.
This means that given a pointer to your data you cannot, for example, delete it from multiple data structures it is contained within without going from these structures roots to re-find the pointers to your data.
Whereas with intrusive data structures (the way it is done in the Linux kernel and other "advanced" C projects), you can easily embed your structure in multiple data structures, such that you can do very quick deletion or modification of the data without re-finding it.
Linux's list.h is extremely useful, and for a wide variety of circumstances, is the most efficient way to manage your data.
In general, I'm anti-boost, but I think it's a personal bias and we use the hell out of it at work to great effect. The one thing I'll give boost::intrusive over sys/queue.h is that the type system helps you a lot more to catch issues and the common case is a bit simpler (a struct that exists in a single linked list and a single hash table, for example).
I've been burned many times by something like the following
struct foo {
TAILQ_ENTRY(foo) lru_entry;
TAILQ_ENTRY(foo) hash_entry;
};
...
void some_magic_func(struct foo *f) {
TAILQ_REMOVE(static_tailq, f, hash_entry); // oops, should be lru_entry!
}
Boost intrusive templatizes on the member as well (IIRC) and eliminates this whole class of problem.I've seen it implemented, but everyone uses the typical non-type-safe one anyway :)
I don't think I've ever had such bugs in a lot of code though, since I tend to wrap the "containerof" call with a little function like: foo_of_lru_entry and foo_of_hash_entry. A bit of boilerplate for each data structure, but worth it.
(Unfortunately it does rely on `typeof`, an extension.)
http://stackoverflow.com/questions/18449038/is-there-ever-a-...