The boost ptr_list documentation states that the container uses an underlying std::list<void*>
.
Why are they using this type instead of a more specialized std::list<T*>
?
It's probably to cut down on the number of template instantiations. If it uses a std::list<T*>
, then every use of ptr_list<T>
would also instantiate std::list<T*>
. That's a lot of instantiations if you use ptr_list
a lot.
This makes it easy to share almost all the code regardless of the type(s) over which you instantiate it. Nearly all the code is in the single std::list<void *>
. Each instantiation only adds code to cast between T *
and void *
where needed.
Of course, modern compilers/linkers can do a fair amount of this without such help, but that hasn't always been the case (and some people still use older tool chains, for various reasons).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With