2 ms·
For data in a single list, they're essentially equivalent, but they differ when one wants to put things in multiple lists. For instance, a collection of Ts mig
by dbaupp 9y ago
For data in a single list, they're essentially equivalent, but they differ when one wants to put things in multiple lists.
For instance, a collection of Ts might want to have a list of the ones with property A and the ones with property B (independently, so any T could be on list A or B, or both, or neither). This could be done by having two std::list<std::shared_ptr<T>> (or something similar, like replacing the shared_ptrs with raw pointers, or indices into an external std::vector<House>), but this pays for the storage for each T, for the prev/next pointers, and also the storage for the pointer to the Houses (plus extra overhead of shared_ptr, etc.). With intrusive lists, one can have next_a/prev_a and next_b/prev_b pointers directly in the Ts and only pay that slight extra cost.
- eropple 9y agoThat's a really good point and I hadn't considered it. Thanks!